Nginx既是反向代理又是Web服务器 [英] nginx be both reverse proxy and web server

查看:76
本文介绍了Nginx既是反向代理又是Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前与nginx配合乘客使用,以服务我的rails应用程序.考虑为该方程式包括一个缓存反向代理.是否可以将同一个Nginx实例用作反向代理(在端口80上运行,提供静态操作以及带有电子标签的操作),还是需要一个不同的Nginx实例或完全不同类型的反向代理?>

谢谢!

解决方案

我认为您可以使用NGINx的相同实例来完成这两个操作,但是您必须将应用程序配置为在其他端口上进行侦听.您可以在端口8080上运行应用程序,仅侦听localhost,在端口80上运行反向代理.

nginx配置的服务器部分可能看起来像这样

 服务器{听127.0.0.1:8080;server_name localhost;根/webapps/foo.com/public;passenger_enabled开启;}服务器 {听80;server_name www.foo.com;地点/{proxy_pass http://127.0.0.1:8080;}} 

请不要钉我确切的语法,这只是为了展示这个主意.

希望这会有所帮助.

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!

解决方案

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.

这篇关于Nginx既是反向代理又是Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆