【建站教程】Nginx 配置多站点反向代理实战

xiuerwj  (UID: 926) 1天前 [复制链接]
帖子链接已复制到剪贴板

70 2

很多朋友在一台 VPS 上跑多个服务(比如 Emby、博客、管理面板),为了让它们通过不同域名访问,就需要用 Nginx 反向代理 来实现。这里分享一个配置示例。

一、准备工作

  1. 一台 VPS / 服务器(建议 Ubuntu / Debian)。
  2. 安装 Nginx: apt update && apt install nginx -y

3.域名解析到服务器 IP

假设我们有两个服务:

  • Emby → 本地端口 8096,域名 emby.example.com
  • 博客 (WordPress) → 本地端口 8080,域名 blog.example.com
  • 在 /etc/nginx/sites-available/ 下新建配置文件:
  • server {
  •    listen 80;
  •    server_name emby.example.com;
  •    location / {
  •        proxy_pass http://127.0.0.1:8096;
  •        proxy_set_header Host $host;
  •        proxy_set_header X-Real-IP $remote_addr;
  •        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  •    }
  • }
  • server {
  •    listen 80;
  •    server_name blog.example.com;
  •    location / {
  •        proxy_pass http://127.0.0.1:8080;
  •        proxy_set_header Host $host;
  •        proxy_set_header X-Real-IP $remote_addr;
  •        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  •    }
  • }
  • 然后执行:
  • ln -s /etc/nginx/sites-available/xxx.conf /etc/nginx/sites-enabled/
  • nginx -t
  • systemctl reload nginx

开启 HTTPS

推荐用 Certbot 自动申请 SSL 证书:

apt install certbot python3-certbot-nginx -y

certbot --nginx -d emby.example.com -d blog.example.com

【建站教程】Nginx 配置多站点反向代理实战

上传时间:2025-09-15
上传用户:xiuerwj
免责声明

此内容由网友转载自网络公开渠道,仅供学习测试,著作权归原作者所有。
本站不对此内容担负法律责任,请于下载后24小时内删除。
如发现内容侵权,请联系本站邮箱:[email protected],我们将在12小时内及时处理。

不集邮兄弟
已有回复 (2)
  • Butachi  (UID: 988) @Ta
    1天前
    沙发
    感谢分享
  • V 奥斯卡卡  (UID: 101) @Ta
    1天前
    椅子
    居然是 nginx 反代,不错不错
发新帖
推广