问题描述
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_headerVary;proxy_hide_headerX-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; }
问题解答
回答1:IP后面还有一个端口把到80端口的请求转发到9095端口,因为nginx本身没法处理java/php/python(举例子而已)的请求,需要交给tomcat,php-fpm或者wsgi等等来处理,所以需要反向代理后端的服务,个人理解
回答2:我觉得也可以写其它IP吧,不一定是本机,只要本机能访问到的都行
回答3:可以其他IP,目的就是实现了代理,简单理解为cdn也可以不过功能是完整的可用的
回答4:127.0.0.1是指本机,为什么要自己代理自己?比如服务器上运行的是node.js服务端,但是node.js不是专门的Web服务器,所以需要Nginx来反向代理一下,这样对于外部访问的控制要方便很多,而且Nginx缓存可以提高性能。