Nginx 是一个高性能的HTTP和反向代理web服务器,在开发时经常会使用它来部署项目,但是只有一个 nginx.conf文件,使用的是Nginx 的默认配置,其中所有站点配置都集中在这个文件中。在 Windows 上,Nginx 的默认配置文件通常位于 C:\Program Files\Nginx\conf\nginx.conf
。要为多个前端应用程序部署配置,我们可以按照以下步骤操作:
-
编辑 nginx.conf 文件:
-
打开您的 nginx.conf 文件,您可以在其中添加多个server 块,为每个前端应用程序设置不同的监听端口和路径。
-
-
配置 server 块:
-
在nginx.conf中,为每个应用程序添加一个server块。例如:
server { listen 8080; server_name firstapp.local; root html/first_app; index index.html index.htm; location / { try_files $uri$uri/ =404; } } server { listen 8081; server_name secondapp.local; root html/second_app; index index.html index.htm; location / { try_files $uri$uri/ =404; } }
-
-
重启 Nginx