Nginx反向代理实例
程序员文章站
2022-05-07 08:09:32
...
添加反向代理配置
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
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;
location / {
proxy_pass http://192.168.3.2:80;
}
示例
解决需求:
访问http://192.168.56.10/ 实际上是访问 http://106.52.36.65:80
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_set_header Host $http_host; #
proxy_set_header X-Real-IP $remote_addr; #实际访问的ip地址
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; #协议
location / {
proxy_pass http://106.52.36.65:80;
}
}
}
访问:
http://192.168.56.10/