Installing Nginx
# 查看相关信息yum info nginxyum info httpd# 移除 httpd,也就是 Apacheyum remove httpd -y# 安装 nginxyum install nginx -y#设置 nginx 自启动chkconfig nginx on# 查看服务自启动情况chkconfig# 启动nginx服务service nginx start# 查看端口监听状态netstat -ntl# 此时你可以访问试试了# 例如: http://192.168.1.111:8080 等# 如果访问不了,请 ping 一下试试# 或者查看 iptables 防火墙状态service iptables status# 关闭防火墙,简单粗暴的service iptables stop
If you do not have permission to perform these operations, you may need to use sudo
permissions
Configure Nginx Reverse Proxy
/etc/nginx/nginx.conf
user nginx;worker_processes 1;error_log /var/log/nginx/error.log;pid /var/run/nginx.pid;events { use epoll; worker_connections 1024;}http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include /etc/nginx/conf.d/*.conf; include upstream.conf; include cncounter.com.conf; }
Configuration of the load: /etc/nginx/upstream.conf
upstream www.cncounter.com { server 127.0.0.1:8080;}
Site configuration file: /etc/nginx/cncounter.com.conf
server{Listen 80; server_name www.cncounter.com; Index index.jsp; root/usr/local/cncounter_webapp/cncounter/; Location ~ ^/nginxstatus/{stub_status on; Access_log off; } location/{root/usr/local/cncounter_webapp/cncounter/; Proxy_redirect off; Proxy_set_header Host $host; Proxy_set_header X-real-ip $remote _addr; Proxy_set_header remote-host $remote _addr; Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; Client_max_body_size 50m; Client_body_buffer_size 256k; Proxy_connect_timeout 30; Proxy_send_timeout 30; Proxy_read_timeout 60; Proxy_buffer_size 256k; Proxy_buffers 4 256k; Proxy_busy_buffers_size 256k; Proxy_temp_file_write_size 256k; Proxy_next_upstream Error timeout Invalid_header http_500 http_503 http_404; Proxy_max_temp_file_size 128m; Proxy_pass http://www.cncounter.com; }}
Restart Service
service nginx stopservice nginx start
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Install Nginx under the CentOS Yum