Install Nginx
Make sure the server's software package is up to date. Sudo yum update -y # sudo RPM -uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # install Nginx sudo yum install Nginx sudo systemctl enable nginx.service -y nginx sudo systemctl enable nginx.serviceCopy the code
Configure Nginx
Conf vim /etc/nginx/conf.d/filename. conf add configuration 1 (configuration 1 and 2 can concurrently listen on port 80, bind different domain names, implement one server nginx to configure multiple front-end websites at the same time, Multiple domain names separated by Spaces) server {listen 80; Server_name Domain name 1 Domain name 2 localhost; location / { proxy_set_header HOST $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Proxy_pass http://127.0.0.1: port /; }} Add configuration 2 server {listen 80; Server_name Domain name 1 Domain name 2 localhost; location / { proxy_set_header HOST $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Proxy_pass http://127.0.0.1: port /; }} proxy static site root specified disk directory server {listen 80; Server_name Domain name 1 Domain name 2 Multiple domain names are separated by Spaces. location / { try_files $uri $uri/ /index.html; root D:\test-web; }}Copy the code
Common commands
Check whether the configuration is wrong sudo nginx -t reload/restart nginx configuration sudo nginx -s reload to see nginx installation directory ps - ef | grep nginxCopy the code
Mistakes and solutions
Unable to access child path error: location /flow {proxy_pass http://127.0.0.1:9083/; } modify: location /flow/ {proxy_pass http://127.0.0.1:9083/; } a/ b/ a/ b/ a/ b Put /a/ /b/ under the root directory. Rewrite ^/(.*)/$/$1 permanent; rewrite ^/(.*)/$/$1 permanent;Copy the code
Separated project deployment at the front and back ends
Gov_flow {alias /var/ HTML /gov_flow; try_files $uri $uri/ /index.html; index index.html; } ## location /stage-prod-api/ {proxy_set_header Host $http_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; proxy_pass http://flow:9083/; } location /stage-test-api/{ proxy_set_header Host $http_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; proxy_pass http://localhost:8080/; } # merge two back-end project interfaces into one to give front-end access to 9991 server {listen 9991; server_name localhost; The location/yqt / {proxy_pass http://127.0.0.1:8888/yqt/; } the location/AD / {proxy_pass http://127.0.0.1:8090/ad/; }}Copy the code
Nginx Example for configuring SSL certificates 1
Server {# SSL: listen 443; The domain name corresponding to the CA certificate server_name www.ilovey.live; Enable SSL SSL on; # server certificate absolute path ssl_certificate/WWW/server/nginx/conf. D / 4467149 _www. Ilovey. Live. Pem; # server certificate to the absolute path to the key ssl_certificate_key/WWW/server/nginx/conf. D / 4467149 _www. Ilovey. Live. The key; Ssl_session_timeout 5m; Ssl_protocols TLSv1 TLSv1.1 TLSv1.2; Ssl_ciphers ecdhe-rSA-aes128-GMC-sha256 :HIGH:! aNULL:! MD5:! RC4:! DHE; Ssl_prefer_server_ciphers on; location ^~ /zhihao/ { proxy_set_header Host $host; Proxy_pass http://127.0.0.1:8080/; }} # this is a necessary operation if the user overwrites the HTTP access directly to HTTPS. server_name www.ilovey.live; rewrite ^/(.*)$ https://www.ilovey.live:443/$1 permanent; }}Copy the code
Nginx Example for configuring SSL certificates 2
server { listen 80; listen 443 ssl http2; server_name ilovey.live; index index.php index.html index.htm default.php default.htm default.html; Root/WWW /wwwroot/ # ssl-start SSL configuration, do not delete or modify the next line of annotated 404 rule #error_page 404/404.html; ssl_certificate /www/server/nginx/conf.d/4467149_www.ilovey.live.pem; ssl_certificate_key /www/server/nginx/conf.d/4467149_www.ilovey.live.key; Ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:! aNULL:! MD5:! RC4:! DHE; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; error_page 497 https://$host$request_uri; # ssl-end # error-page-start ERROR PAGE configuration, can comment, delete, or modify #error_page 404/404.html; #error_page 502 /502.html; # error-page-end # php-info-start # proxy-start location / {proxy_pass http://localhost:8886; 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_set_header REMOTE-HOST $remote_addr; #proxy_connect_timeout 30s; #proxy_read_timeout 86400s; #proxy_send_timeout 30s; # proxy_http_version 1.1; #proxy_set_header Upgrade $http_upgrade; #proxy_set_header Connection "upgrade"; ##expires 12h; } # # PHP - INFO - END blocking access to the file or directory location ~ ^ / (\. User. Ini | \. Htaccess file | \. Git | \. SVN | \. Project | LICENSE | README. Md) {return 404; } # location ~ \. Well-known {allow all; }}Copy the code
Source: ilovey. Live / 2021/09/09 /…
Recent hot articles recommended:
1.1,000+ Java Interview Questions and Answers (2021)
2. Don’t use if/ else on full screen again, try strategy mode, it smells good!!
3. Oh, my gosh! What new syntax is xx ≠ null in Java?
4.Spring Boot 2.5 is a blockbuster release, and dark mode is exploding!
5. “Java Development Manual (Songshan version)” the latest release, quick download!
Feel good, don’t forget to click on + forward oh!