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

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

 

posted @ 2017-09-26 16:20  丶老中医  阅读(749)  评论(0编辑  收藏  举报
一切已经开始©2018 丶老中医