How to use proxy to forward request in Nginx
How do I forward requests using proxies in Nginx? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Nginx uses proxy to forward request instance
As one of the most popular web servers at present, nginx can easily implement reverse proxy.
Nginx reverse proxy official document: NGINX REVERSE PROXY
When several different web servers are deployed on one host and need to be able to access these web servers at the same time, the reverse proxy function of nginx can be used to use nginx to listen for all requests on port 80 and forward them to port 443.Then port 443 will uniformly forward them to the corresponding domestic web servers according to the forwarding rules.
1. Domestic Beijing Ali Cloud Server (proxy.mimvp.com)
There can be multiple vim mimvp_proxy.confserver {listen 80; server_name proxy.mimvp.com; # domain names, separated by spaces root www/mimvp_proxy; rewrite ^ (. *) $https://$host$1 permanent; location / {root www/mimvp_proxy; index index.php index.html index.htm;} location ~. Php$ {root www/mimvp_proxy Fastcgi_pass 127.0.0.1 location 9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name; include fastcgi.conf;} location ~ * ^ / (images | img | javascript | css | blog | flash | media | static) / {root www/mimvp_proxy; expires 30d;} location ~ * ^ / (robots\ .txt) {root www/mimvp_proxy; expires 365d;} location ~ * ^ / favicon\ .ico {root www/mimvp_proxy Expires 365d;} location ~ * ^ / img/logo\ .png {root www/mimvp_proxy; expires 365d;} location ~ /\ .ht {deny all;}} server {listen 443 ssl http2; server_name proxy.mimvp.com; # domain names can be multiple, separated by spaces Ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHEMUR location ~\. Php$ {root www/mimvp_proxy; fastcgi_pass 127.0.0.19000 Fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name; include fastcgi.conf;} location ~ * ^ / (images | img | javascript | js | css | blog | flash | media | static) / {root www/mimvp_proxy; expires 30d;} location ~ * ^ / (robots\ .txt) {root www/mimvp_proxy; expires 365d;} location ~ * ^ / favicon\ .ico {root www/mimvp_proxy; expires 365d } location ~ * ^ / img/logo\ .png {root www/mimvp_proxy; expires 365d;} location ~ /\ .ht {deny all;}}
two。 Overseas Singapore Tencent Cloud Server (proxy.mimgu.cn)
Vim mimvp_proxy2.confserver {listen 80; server_name proxy.mimgu.cn; root www/mimvp_proxy; rewrite ^ (. *) $https://$host$1 permanent; # # all requests are forcibly redirected to https} server {listen 443 ssl http2; server_name proxy.mimgu.cn; root www/mimvp_proxy; ssl on; ssl_certificate proxy.mimgu.cn.crt; ssl_certificate_key proxy.mimgu.cn.key; ssl_session_cache shared:SSL:1m Ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ssl_prefer_server_ciphers on; location / {proxy_pass https://proxy.mimvp.com;; ssl_prefer_server_ciphers on; location / {ECDHEMUR; ssl_prefer_server_ciphers on; location / {ECDHEMUR / {ECDHEMUR / {ECDHER] # # all requests are forcibly redirected to the domestic server https://proxy.mimvp.com} location ~\. Php$ {proxy_pass https://proxy.mimvp.com;} location * ^ / (images | img | javascript | js | css | blog | flash | media | static) / {proxy_pass https://proxy.mimvp.com; # # all css,js,img must be forcibly forwarded, otherwise typesetting may be mistypesetting} location ~ * ^ / (robots\ .txt) {proxy_pass https://proxy.mimvp.com;} location ~ * ^ / favicon\ .ico {proxy_pass https://proxy.mimvp.com;} location ~ * ^ / img/logo\ .png {proxy_pass https://proxy.mimvp.com;} location ~ /\ .ht {deny all;}}
3. View the effect
Http proxy.mimvp.com / / forcibly redirect to the only domain name URL displayed in https proxy.mimvp.comhttps proxy.mimvp.com / / http proxy.mimgu.cn / / forcibly redirect to https proxy.mimgu.cn, and then continue to forcibly redirect to https proxy.mimvp.comhttps proxy.mimgu.cn / / forcibly redirect to https proxy.mimvp.com. After reading the above, do you know how to use agents to forward requests in Nginx? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!