本文章主要介绍了nginx proxy转发配置,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!
nginx proxy转发配置
打开配置:
$ cd /usr/local/nginx/conf
$ vim nginx.conf
添加:
server { listen 80 default_server; #listen [::]:80 default_server ipv6only=on; server_name _; index index.html index.htm index.php; root /home/samba; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*/.php$ { deny all; } include enable-php.conf; location /nginx_status { stub_status on; access_log off; } location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*/.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ //. { deny all; } location /one/ { proxy_pass http://192.168.1.153/; proxy_set_header Host $host:$server_port; #proxy_redirect http://dsm/ http://$host:8080/abc; #proxy_redirect http://$host:8080/ http://127.0.0.1:8080/abc/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /two/ { proxy_pass http://192.168.1.154/; proxy_set_header Host $host:$server_port; #proxy_redirect http://dsm/ http://$host:8080/abc; #proxy_redirect http://$host:8080/ http://127.0.0.1:8080/abc/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log /home/wwwlogs/access.log; } include vhost/*.conf; }
重启nginx:
$ service nginx reload
访问测试:
$ curl localhost/one
返回内容:你设置的转发的服务器的响应!
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/228359.html