我正在Debian服务器(ip 192.168.1.193)中运行一个rails应用程序,其中passenger作为独立的应用程序
$ cd /home/hector/webapps/first $ passenger start -a 127.0.0.1 -p 3000
我想为这个应用程序抛出Nginx的反向代理在不同的子文件夹中:
http://192.168.1.193/first
我的nginx.conf服务器:
... server { listen 80; server_name 127.0.0.1; root /home/hector/webapps/first/public; passenger_base_uri /first/; location /first/ { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; } } ...
然后我运行Nginx服务器
$ /opt/nginx/sbin/nginx
有了一个轨道应用程序运行这个configuration一切似乎工作正常。
但是,当我尝试添加我的第二个应用程序
$ cd /home/hector/webapps/second $ passenger start -a 127.0.0.1 -p 3001
用这个nginx.conf文件:
... server { listen 80; server_name 127.0.0.1; root /home/hector/webapps/first/public; passenger_base_uri /first/; location /first/ { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; } } server { listen 80; server_name 127.0.0.1; root /home/hector/webapps/second/public; passenger_base_uri /second/; location /second/ { proxy_pass http://127.0.0.1:3001; proxy_set_header Host $host; } } …
并重新加载Nginx服务器configuration
$ /opt/nginx/sbin/nginx -s reload nginx: [warn] conflicting server name "127.0.0.1" on 0.0.0.0:80, ignored
我收到警告,我无法访问第二个应用程序
http://192.168.1.193/second/
服务器为第二个应用程序返回404,第一个应用程序仍在运行。
我想你只需要把两个位置放到同一台服务器上:
server { listen 80; server_name 127.0.0.1; location /first/ { root /home/hector/webapps/first/public; passenger_base_uri /first/; proxy_pass http://127.0.0.1:3000/; proxy_set_header Host $host; } location /second/ { root /home/hector/webapps/second/public; passenger_base_uri /second/; proxy_pass http://127.0.0.1:3001/; proxy_set_header Host $host; } }