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;
}
}