nginx反向代理的proxy_pass後面的url是什麼的url?以下範例中所寫的127.0.0.1,表示本機?自己代理自己?作用是什麼呢?
location / {
proxy_http_version 1.1;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
add_header X-Frame-Options deny;
add_header X-Content-Type-Options nosniff;
add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https: http://ip.qgy18.com; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self' https://translate.googleapis.com; frame-src https://disqus.com https://www.slideshare.net";
add_header Public-Key-Pins 'pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="aef6IF2UF6jNEwA2pNmP7kpgT6NFSdt7Tqf5HzaIGWI="; max-age=2592000; includeSubDomains';
add_header Cache-Control no-cache;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Vary;
proxy_hide_header X-Powered-By;
proxy_set_header X-Via QingDao.Aliyun;
proxy_set_header Connection "";
proxy_set_header Host imququ.com;
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:9095;
}
IP後面還有一個端口
把到80端口的請求轉發到9095端口,因為nginx本身沒法處理java/php/python(舉例子而已)的請求,需要交給tomcat,php-fpm或者wsgi等等來處理,所以需要反向代理後端的服務,個人理解
我覺得也可以寫其它IP吧,不一定是本機,只要本機能訪問到的都行
可以其他IP,目的就是實現了代理,簡單理解為cdn也可以不過功能是完整的可用的
127.0.0.1是指本機,為什麼要自己代理自己?例如伺服器上運行的是node.js服務端,但是node.js不是專門的Web伺服器,所以需要Nginx來反向代理一下,這樣對於外部存取的控制要方便很多,而且Nginx快取可以提高效能。