nginx 一个80端口布置通过ip访问的2个网站其中a是网站A 其余路由都是网站b的前端路由
可以使用nginx的虚拟主机功能来实现这个需求。
首先,需要在nginx的配置文件中配置虚拟主机,指定两个网站的根目录和访问端口:
server {
listen 80;
server_name your_ip_address;
location /a {
root /path/to/websiteA;
index index.html;
}
location / {
proxy_pass http://localhost:8080;
}
}
这个配置文件中,我们使用了listen指令来指定nginx监听80端口,server_name指令指定了需要处理的请求的域名或IP地址。对于网站A,我们使用了location /a来指定访问路径,使用root指令来指定网站A的根目录,index指令指定默认的首页文件名。对于网站B,我们使用了location /来指定访问路径,使用proxy_pass指令将请求转发到本地的8080端口,这个端口上运行着网站B的前端路由。
最后,需要重启nginx服务使配置生效。
sudo systemctl restart nginx
这样就可以通过访问http://your_ip_address/a来访问网站A,访问http://your_ip_address/及其它路径来访问网站B的前端路由了
原文地址: https://www.cveoy.top/t/topic/fyyx 著作权归作者所有。请勿转载和采集!