nginx安装
最后是安装nginx
,这里我们还是使用最简单的yum
的方式来进行安装。
- 首先使用以下几个命令安装必备的几个库:
yum -y install pcre* yum -y install openssl* yum -y install gcc
- 之后安装nginx。
cd /usr/local/ wget http://nginx.org/download/nginx-1.4.2.tar.gz tar -zxvf nginx-1.4.2.tar.gz cd nginx-1.4.2 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module make make install
- 之后就可以使用
/usr/local/nginx/sbin/nginx
命令来启动nginx了。输入服务器的IP地址,如果出现nginx的欢迎界面表示安装成功了。
nginx配置
这里我就简单贴以下我的配置,主要就是配置一个upstream,
之后在server
中引用配置的那个upstream
即可。
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream crossover_main { server 127.0.0.1:8080; } server { listen 80; server_name www.crossoverjie.top; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://crossover_main/examples/; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $remote_addr; index index.jsp; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
之后我们在地址栏输入服务器的IP地址(如果有域名解析了服务器的IP可以直接输入域名)就会进入我们在upstream
中配置的地址加上在server
中的地址。根据我这里的配置最后解析地址就是http://127.0.0.1:8080/examples
应该是很好理解的。最终的结果是我在片头放的那张截图一样。
总结
这是一个简单的基于centOS的运行环境配置,对于小白练手应该是够了,有不清楚和错误的地方欢迎指出。
个人博客地址:crossoverjie.top。
GitHub地址:github.com/crossoverJi…。