1.下載安裝nginx
[root@app-bj-ali-ecs1 ~]# yum install -y pcre pcre-devel zlib-devel [root@app-bj-ali-ecs1 ~]# wget http://nginx.org/download/nginx-1.26.1.tar.gz [root@app-bj-ali-ecs1 ~]# tar -zxvf nginx-1.26.1.tar.gz [root@app-bj-ali-ecs1 ~]# cd nginx-1.26.1 [root@app-bj-ali-ecs1 nginx-1.26.1]# ./configure && make && make install [root@app-bj-ali-ecs1 ~]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@app-bj-ali-ecs1 ~]# /usr/local/nginx/sbin/nginx [root@app-bj-ali-ecs1 ~]# netstat -tpln | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 46787/nginx: master [root@app-bj-ali-ecs1 ~]# curl 127.0.0.1:80 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
2.配置靜態資源
[root@nginx-bj-ali-ecs1 bak]# cat taciturn.bfmq.cloud.conf.bak ################################### taciturn.bfmq.cloud server conf ######################################## server { server_name taciturn.bfmq.cloud; index index.html index.htm index.jsp login_redirect.jsp main.jsp; # if you want to use https,just need remove these comments listen 443 ssl; ssl_certificate ssl/bfmq-cloud-cert.pem; ssl_certificate_key ssl/bfmq-cloud-key.pem; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL; ssl_prefer_server_ciphers on; location ~ ^/WEB-INF/* { deny all; } location / { root /home/work/taciturn-bfmq-cloud/dist/; # 靜態資源目錄 proxy_redirect off; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_intercept_errors on; } client_max_body_size 500m; client_body_buffer_size 512k; proxy_connect_timeout 6; proxy_send_timeout 600; proxy_read_timeout 600; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; error_page 404 500 502 503 504 /50x.html; location = /50x.html { root html; } access_log /var/log/nginx/taciturn.bfmq.cloud/taciturn.bfmq.cloud.access.log; error_log /var/log/nginx/taciturn.bfmq.cloud/taciturn.bfmq.cloud.error.log; }
3.配置反向代理資源
[root@nginx-bj-ali-ecs1 bak]# cat taciturn-story.bfmq.cloud.conf.bak ################################## taciturn-story.bfmq.cloud upstream conf ######################################## upstream taciturn-story-bfmq-cloud { server 172.25.36.150:20001; # 代理目標 } ################################### taciturn-story.bfmq.cloud server conf ######################################## server { server_name taciturn-story.bfmq.cloud; index index.html index.htm index.jsp login_redirect.jsp main.jsp; # if you want to use https,just need remove these comments listen 443 ssl; ssl_certificate ssl/bfmq-cloud-cert.pem; ssl_certificate_key ssl/bfmq-cloud-key.pem; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL; ssl_prefer_server_ciphers on; location ~ ^/WEB-INF/* { deny all; } location / { proxy_pass http://taciturn-story-bfmq-cloud; proxy_redirect off; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_intercept_errors on; } client_max_body_size 500m; client_body_buffer_size 512k; proxy_connect_timeout 6; proxy_send_timeout 600; proxy_read_timeout 600; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; error_page 404 500 502 503 504 /50x.html; location = /50x.html { root html; } access_log /var/log/nginx/taciturn-story.bfmq.cloud/taciturn-story.bfmq.cloud.access.log; error_log /var/log/nginx/taciturn-story.bfmq.cloud/taciturn-story.bfmq.cloud.error.log; }