MENU

Catalog

    lnmp环境nginx反向代理配置

    September 7, 2019 • linux相关

    • 环境:军哥的 lnmp 一键编译脚本
    • 场景:nginx 反代本机 http 127.0.0.1:8081
    • 域名:xxx.com
    • 前提:先按正常方式添加对应域名的虚拟机 lnmp vhost add
      对应的 /usr/local/nginx/conf/vhost/xxx.com.conf 文件,清空自动生成的内容,填写以下配置:

      map $scheme $go_proxy_port {
        "http"  "8081";
        "https" "8082";
        default "8081";
      }
      server
        {
            listen 80;
            #listen [::]:80;
            server_name xxx.com;
            
            location / {
                proxy_pass              $scheme://127.0.0.1:$go_proxy_port;
                proxy_redirect          ~^$scheme://127.0.0.1:$go_proxy_port(.*)    http://xxx.com$1;
                proxy_set_header        Host             $http_host;
                proxy_set_header        X-Real-IP        $host;
                proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
        }
    • 测试配置合法性

      /usr/local/nginx/sbin/nginx -t
    • 重载 nginx 配置

      service nginx reload
    Last Modified: April 4, 2020