大家都知道80端口是可以通过域名直接访问的(无需加端口号),正常80端口只能使用于一个域名,但通过nginx配置可以实现多个。以阿里云ECS服务器为例,通过命令安装nginx后,打开nginx配置文件
vim /etc/nginx/conf.d/default.conf
按以下方式配置多个域名跳转
# 官网1跳转
server {
listen 8088;
root /data/webdata/apps/官网源码1
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
# 官网2 跳转
server {
listen 8089;
root /data/webdata/apps/官网源码2
index index.html;
location / {}
}
# nginx 80
server {
listen 80;
server_name 跳转官网1的域名
charset utf-8;
index index.html;
location / {
proxy_pass [http://localhost:8088;](http://localhost:8088;)
}
}
# nginx 80
server {
listen 80;
server_name 跳转官网2的域名
charset utf-8;
index index.html;
location / {
proxy_pass [http://localhost:8089;](http://localhost:8089;)
}
}
2、 按配置的路径上传源码
3、 在阿里云ecs服务器上安全组配置,开放配置的端口。路径 ECS服务 - 更多 - 网络和安全组 - 安全组配置 - 配置规则 - 添加你想开放的端口。
4、域名添加对应解析
5、重启nginx。完成。
nginx -s reload