阿里云 ECS 怎么用 nginx 部署80端口多个网站

发布于:2025-08-10 ⋅ 阅读:(17) ⋅ 点赞:(0)

怎么用一个域名情况下根据不同地址怎么部署多个网站

首先安装 nginx

Alibaba Cloud Linux 3 生成 nginx-CSDN博客

其次删除 /etc/nginx/nginx.conf 下的 80 端口 serve 配置

然后在 /etc/nginx/nginx.conf/conf.d 目录下创建 default.conf

server {
    listen       80;
    server_name  localhost;

    access_log  /var/log/nginx/host.access.log  main;
    location / {
        proxy_pass http://127.27.25.192:5001/;
    }

    location /commit {
        proxy_pass http://127.27.25.192:5001/;
    }

    location /github {
	proxy_pass http://127.27.25.192:5002/;
    }

    location /tools {
        proxy_pass http://127.27.25.192:5003/;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

我的域名是 huyunan.xyz ,需要先备案 ,然后解析到阿里云服务器的外网IP地址,下面的127.27.25.192 是我的内网IP地址。

访问 http://huyunan.xyz 后默认路径是 / 跳转到 http://127.27.25.192:5001/

访问 http://huyunan.xyz/commit  也是跳转到 http://127.27.25.192:5001/ 所以 /commit 这个网站是默认的。

然后其它路径比如 http://huyunan.xyz/tools  跳转到 http://127.27.25.192:5003/ 这个网站

现在还需要阿里云服务器允许这5001 这几个端口入站出站

入方向和出方向都要添加

然后配置具体网站静态文件路径,添加 github-commit.conf 文件

server {
    listen       5001;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /app/commit/dist;
      	try_files $uri $uri/ = 404;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
}

自备网站静态文件,注意网站打开地址必须是 http://localhost:8080/commit/ 这种带 /commit 路径的与上面配置的 /commit 名称对上,不然不好使。

编译后生成的 dist 文件夹放到 /app/commit 目录下。

重启 nginx 配置

systemctl reload nginx

如果你的网站备案成功可以直接用域名访问,不然也可以用公网IP访问

http://huyunan.xyz/commit/


网站公告

今日签到

点亮在社区的每一天
去签到