如何在服务器同一个端口下根据路径区分不同的应用

通常我们使用域名直接访问网站时,使用的是80或者443端口。但一个主站下面可能有好几个子网站,我们如何通过路径来挂载子网站呢?

nginx.conf配置

使用nginx代理能够实现根据不同的路径,访问同一端口下的子网站。

root配置网站的默认根目录,alias指定子网站路径。

bash 复制代码
server {
        listen 80 default_server;
		charset utf-8;
		
		# 默认访问路径
		location / {
			root  /usr/local/official;
			try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }

		# 请求后台访问
        location /api/ {
			proxy_set_header Host $http_host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE_HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header X-NginX-Proxy true;
            # 反向代理配置
			proxy_pass http://localhost:3637/;
        }
		
		# 子网站路径
        location /vr {
			alias /usr/local/vr;
			try_files $uri $uri/ /our.html;
            index  our.html;
        }
        add_header Access-Control-Allow-Origin "*";
        default_type 'text/html';
        
		error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
相关推荐
qq_589568101 小时前
centos6.8镜像源yum install不成功,无法通过镜像源下载的解决方式
linux·运维·centos
weixin_516023072 小时前
linux下fcitx5拼音的安装
linux·运维·服务器
hunter14502 小时前
Linux 进程与计划任务
linux·运维·服务器
楼田莉子3 小时前
Linux学习之磁盘与Ext系列文件
linux·运维·服务器·c语言·学习
陌上花开缓缓归以3 小时前
linux 怎么模拟系统panic重启
linux·运维·服务器
月白风清江有声3 小时前
vscode使用git
linux·运维·服务器
开开心心_Every5 小时前
免费窗口置顶小工具:支持多窗口置顶操作
服务器·前端·学习·macos·edge·powerpoint·phpstorm
haluhalu.5 小时前
深入理解Linux线程机制:线程概念,内存管理
java·linux·运维
cui__OaO6 小时前
Linux驱动--驱动编译
linux·运维·服务器
Q16849645157 小时前
红帽Linux-进程、ssh、网络、软件包、文件系统
linux·运维·网络