nginx 配置go服务反向代理

nginx 配置

详细请看Nginx 极简教程

复制代码
server {
      listen       80;
      server_name  localhost;

      #charset koi8-r;
      
      # nginx访问活动日志
      access_log  logs/host.access.log  main;
      # nginx访问错误日志
      error_log  logs/error.log;

      # 配置前端访问
      location / {
          root   /root/server/dist;
          index  index.html index.htm;
      }
      location /dist {
          root   /root/server/dist;
          index  index.html index.htm;
      }
      # 正则匹配api
      location /api {
          proxy_set_header Host $http_host;
          proxy_set_header  X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          rewrite ^/api/(.*)$ /$1 break;  # url重写
          proxy_pass http://127.0.0.1:8888; # 设置代理服务器的协议和地址
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection upgrade;
     }
     error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
posted @   牛奔  阅读(214)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2020-08-16 Mac port 443: Connection refused
点击右上角即可分享
微信分享提示