公司测试环境使用nginx部署多个前端项目。网上查到了两个办法:

在配置文件中增加多个location,每个location对应一个项目
比如使用80端口,location / 访问官网; location /train 访问培训管理系统
配置多个站点
我选择了配置多个location。

location / { root /data/html/; index index.html index.html; } location /train {

  1. root /data/trainning/;
  2. index index.html index.html;

}

配置完以后访问。http://xxxx/train 提示404
找了好久才搞明白, location如果一个特定的url 要使用别名,不能用root,alias指定的目录是准确的,root是指定目录的上级目录,改动后即可以使用了

location /train {

  1. alias /data/trainning/;
  2. index index.html index.html;

}

————————————————

server {

listen 8008;

server_name 192.168.0.127;

charset koi8-r;

access_log logs/host.access.log main;

location / {

  1. root html;
  2. index index.html index.htm;

}

location /manage {

  1. root D:/nginx-1.16.1/html/manage;
  2. index index.html index.htm;

}

location /dljg {

  1. root D:/nginx-1.16.1/html/dljg;
  2. index index.html index.htm;

}

}

版权声明:本文为CSDN博主「老刀-007」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lizhiyuan_eagle/article/details/90639448