更新:目前我访问我的应用程序在domain.com:3000,但我想访问domain.com看到我的应用程序
我已经在80上设置nginx来代理我的rails应用程序在3000.下面是configuration
upstream railsapp { server 127.0.0.1:3000; } server { listen 80; server_name APP; # Tell Nginx and Passenger where your app's 'public' directory is root /var/www/APP/current/public; index index.html index.htm; # Static assets are served from the mentioned root directory location / { root /var/www/APP/current; index index.html index.htm; proxy_pass http://railsapp/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; # proxy_set_header X-Real-Port $server_port; # proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-NginX-Proxy true; } # Turn on Passenger passenger_enabled on; passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby; }
我提到: https : //stackoverflow.com/a/5015178/1124639
这个文件位于/etc/nginx/sites-enabled/APP.conf
,在http{...}
包含在/etc/nginx/nginx.conf中
include /etc/nginx/sites-enabled/*;
但是我的APP.com仍然显示“Welcome to nginx on Ubuntu!” 和APP.com:3000显示我的应用程序。 我究竟做错了什么?
我正在使用的是:
Ubuntu 14.04 ec2实例
nginx 1.8.0
在3000的独angular兽服务器
我试图运行独角兽,所以我可以将我的应用程序分叉到多个实例。 我想这里的问题是,我设置了passenger_enabled,实际上是在3000上运行独角兽。
所以,而是我跑了乘客
passenger start -a 127.0.0.1 -p 3000 -d -e production
和我的nginx conf这样,
server { listen 80; server_name www.APPNAME.com; # Tell Nginx and Passenger where your app's 'public' directory is root /var/www/APPNAME/current/public; index index.html index.htm; # Static assets are served from the mentioned root directory location / { # root /var/www/APPNAME/current; # index index.html index.htm; proxy_pass http://127.0.0.1:3000; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; # proxy_set_header X-Real-Port $server_port; # proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-NginX-Proxy true; } # Turn on Passenger passenger_enabled on; passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby; }
现在一切正常
您只需添加一个新的服务器块并添加passenger_root。 这就是我所做的。 然后配置完成后,在浏览器上尝试server_name:port“APP.com:3000”。
upstream railsapp { server 127.0.0.1:3000; } // add new server block here... modify with below example. server { listen *:3000; server_name APP.com; rack_env development; root /directory/to/rails-app/public; index index.html index.htm index.html.erb; passenger_enabled on; } server { listen 80; server_name APP; # Tell Nginx and Passenger where your app's 'public' directory is root /var/www/APP/current/public; index index.html index.htm; # Static assets are served from the mentioned root directory location / { root /var/www/APP/current; index index.html index.htm; proxy_pass http://railsapp/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; # proxy_set_header X-Real-Port $server_port; # proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-NginX-Proxy true; } # Turn on Passenger passenger_enabled on; //add passenger_root passenger_root /directory/to/phusion_passenger/locations.ini; passenger_ruby /usr/local/rvm/gems/ruby-2.1.3/wrappers/ruby; }