[英]Rails app served via Passenger standalone behind an nginx proxy
我有兩個應用程序: /foo
和/bar
。 在每個文件夾中,我都在啟動乘客。 對於foo:
passenger start -d -e production -p 4000
對於酒吧:
passenger start -d -e production -p 4001
然后,我將nginx配置如下:
server {
listen 80 default_server;
server_name www.server.com;
root /var/www/html;
location /foo/ {
proxy_pass http://0.0.0.0:4000/;
proxy_set_header Host $host;
}
location /bar/ {
proxy_pass http://0.0.0.0:4001/;
proxy_set_header Host $host;
}
}
這些應用程序已開始提供服務,但沒有任何鏈接可用。 指向users#index
操作的鏈接以'/users'
而不是'/foo/users'
。
_url
和_path
方法,但都沒有用。 因此,我遵循了用於Passenger的nginx配置的高級配置說明 ,並添加了passenger_base_uri = '/foo';
到我的自定義conf文件並按如下方式加載:
乘客啟動-d -e生產-p 4000 --nginx-config-template nginx.conf.erb
仍然沒有愛,我沒有主意。 有人做過嗎? 這似乎是在生產環境中部署多個應用程序的常用方法。
更多想法(2015-06-05)
在我的nginx.conf.erb文件中添加passenger_base_uri = '/foo'
會將應用程序托管在兩個位置(這對我來說很奇怪,但無論如何):
localhost:4000/
localhost:4000/foo/
第一個沒有正確的資源鏈接(即只是'/users'
),但是可以訪問其資產。
第二個有正確的資源鏈接(例如'/foo/users'
),但沒有資產(這是因為它在尋找/foo/assets/*
公共文件夾,而不僅僅是內部/assets/*
)。 我相信這是要走的路,因為我可以像這樣更改代理以獲取應用程序:
location /foo/ {
proxy_pass http://0.0.0.0:4000/foo/;
proxy_set_header Host $host;
}
還有其他人有什么想法嗎? 如果這樣做,這意味着我必須將我的資產放到public / foo中才能起作用。 不是世界末日,但看起來仍然很奇怪。
對於想要做同樣事情的其他人,這就是最后的結果:
passenger_base_uri = '/foo';
) config.assets.prefix = '/foo/assets'
。 passenger start -d -e production -p SOME_PORT --nginx-config-template nginx.conf.erb
在您的nginx代理配置中,為您的應用添加一個位置指令:
location /foo/ { proxy_pass http://0.0.0.0:SOME_PORT/foo/; proxy_buffering off; proxy_http_version 1.1; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; # more robust than http_host proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # this ensures your app's env is correct proxy_set_header X-Forwarded-Host $host; # proxy_set_header X-Forwarded-Proto https; # add this if you always want the redirects to go to HTTPS }
之后,(重新)啟動您的nginx代理,您應該擅長http://your_proxy/foo/
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.