我在同一主机上运行了多个 ruby 应用程序:
~/app1
~/app2
~/app3
Run Code Online (Sandbox Code Playgroud)
我想让 nginx 使用子目录代理这些应用程序,例如:
http://example.com/app1
http://example.com/app2
http://example.com/app3
Run Code Online (Sandbox Code Playgroud)
我很好奇 nginx 是否支持我在多个文件中定义这些位置,以便我可以将每个配置保留在应用程序中,而不是为所有应用程序拥有一个单一的配置文件:
~/app1/nginx.conf
~/app2/nginx.conf
~/app3/nginx.conf
Run Code Online (Sandbox Code Playgroud)
我在 3 个配置文件中的每一个中都使用单个位置指令定义服务器的天真尝试导致conflicting server name "example.com" on [::]:80, ignored
配置如下所示:
upstream app1 { server 127.0.0.1:4567; }
server {
listen [::]:80;
listen 80;
servername example.com
location /app1 {
proxy_pass http://app1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法以这种方式组织配置?