IT虾米网

nginx proxy转发配置详解

xmjava 2021年09月05日 程序员 345 0
本文章主要介绍了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

返回内容:你设置的转发的服务器的响应!


发布评论
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

linux用户和用户组详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。