有几个项目都是跑在一台服务器上,只是根据域名前缀的不同,来访问不同的页面
例如:
erp.abc.com 返回erp的页面
mall.abc.com 返回商城购买的页面
work.abc.com 返回商城后台管理的页面
以下是后台管理服务nginx的配置
server {
listen 80;
server_name work.abc.com;
#charset koi8-r;
root /resources/work;
index index.html;
#access_log logs/host.access.log main;
client_max_body_size 5m;
location / {
proxy_pass http://127.0.0.1:3004;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.(gif|jpg|png|GIF|JPG|PNG|ico|bmp|js|css|html|htm|ttf|woff|txt)$ {
root /resources/work;
}
}
server {
listen 80;
server_name erp.abc.com;
#charset koi8-r;
root /resources/erp;
index index.html;
#access_log logs/host.access.log main;
client_max_body_size 5m;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.(gif|jpg|png|GIF|JPG|PNG|ico|bmp|js|css|html|htm|ttf|woff|txt)$ {
root /resources/erp;
}
}
区别在于反向代理的端口不同,还有域名前缀不同,以及vue项目打包好之后的跟目录不同,
问题如下:
现在直接访问work.abc.com 浏览器会返回notfound
必须得加/index.html后缀
自己有尝试修改nginx配置,发现跟这句配置有关
proxy_pass http://127.0.0.1:3004;
如果屏蔽了,就可以正常通过域名直接访问,无需后缀,但项目很显然不会有响应了,
想请教,如何能直接通过域名访问,又有反向代理,让服务正常响应