如何在nginx中包含位置块?

nat*_*dev 1 reverse-proxy nginx

nginx用作 2 个网络应用程序的反向代理。
这两个 Web 应用程序 (ui) 是共享位置代理,
因为后端服务是共享的。

如何组合位置块并将它们包含在服务器中?

主机配置文件

server {
  server_name app1.com
  listen 8080;
  ...

  include /opt/bitnami/nginx/conf/vhosts/proxy.conf;
}

server {
  server_name app2.com;
  listen 8080;
  ...

  include /opt/bitnami/nginx/conf/vhosts/proxy.conf;
}
Run Code Online (Sandbox Code Playgroud)

代理配置文件

location /api/videos {
  proxy_pass ...
}
...
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

"location" directive is not allowed here in /opt/bitnami/nginx/conf/vhosts/proxy.conf:2

小智 9

您需要更改文件扩展名,更改proxy.confproxy.locations.

  • 我在文档中找不到任何内容,但观察到根“nginx.conf”配置文件在“http”部分中有“include /etc/nginx/conf.d/*.conf;”。这意味着除“.conf”之外的任何扩展名都可以工作,因为“*.conf”本身将自动包含在“http”部分中。 (4认同)