gpt4 book ai didi

ruby-on-rails - 如何将 nginx 配置为代理到 Rails 应用程序?这样我就不必说 domain.com :port

转载 作者:行者123 更新时间:2023-12-04 07:33:18 25 4
gpt4 key购买 nike

更新:目前我在 domain.com:3000 访问我的应用程序,但我想访问 domain.com 来查看我的应用程序
我已将 nginx 设置为 80 以在 3000 处代理我的 rails 应用程序。以下是配置

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并包含在/etc/nginx/nginx.conf 中,如下所示 http{...}
include /etc/nginx/sites-enabled/*;

但我的 APP.com 仍然显示“欢迎使用 Ubuntu 上的 nginx!”和 APP.com:3000 显示我的应用程序。我究竟做错了什么?

我正在使用什么:
Ubuntu 14.04 ec2 实例
nginx 1.8.0
unicorn 服务器 3000

最佳答案

我试图运行 unicorn ,所以我可以将我的应用程序 fork 到多个实例。我想这里的问题是,我设置了passenger_enabled 并且实际上是在3000 上运行 unicorn 。

所以我跑了乘客

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;
}

现在一切正常!

关于ruby-on-rails - 如何将 nginx 配置为代理到 Rails 应用程序?这样我就不必说 domain.com :port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32109403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com