nginx代理配置
配置文件目录:etc/nginx/conf.d
sercer {
listen 9100;
server_name localhost;
location / {
proxy_pass http://{ip}:{port};
proxy_redirect off;
# WebSocket Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"
proxy_set_header Host $host;
proxy_set_header X-Real-IP$remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
解释:
listen:需要服务监听的端口号,默认80;
server_name:此处存放域名,localhost对应本地ip,用户通过域名访问服务器时,会通过DNS服务器解析域名找到对应的服务器ip。
通过以上配置让nginx作为代理服务器访问到对应ip