nginx be both reverse proxy and web server

别等时光非礼了梦想. 提交于 2019-12-11 10:36:06

问题


I currently use nginx with passenger to serve my rails app. considering including a caching reverse proxy to the equation. Can I use the same instance of nginx as a reverse proxy (running on port 80, serving static as well as e-tagged actions) as well or would I need a different instance of nginx or a totally different type of reverse proxy?

Thanks!


回答1:


I think You can use the same instance of NGINx to do both but You will have to configure your application to listen on a different port. You can run your application on port 8080 listening to localhost only and the reverse proxy on the port 80.

A server part of your nginx configuration might look like this

server {
  listen 127.0.0.1:8080;
  server_name localhost;
  root /webapps/foo.com/public;
  passenger_enabled on;
}

server {
  listen 80;
  server_name www.foo.com;
  location / {
    proxy_pass http://127.0.0.1:8080;
  }
}

Please do not nail me on the exact syntax, this is just to show the Idea.

Hope this helps.



来源:https://stackoverflow.com/questions/3912342/nginx-be-both-reverse-proxy-and-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!