Nginx反向代理配置示例

 

server
{
    listen 80;
    server_name 123.xxx.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/123.xxx.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    #清理缓存规则

    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$1$is_args$args;
        #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
          #access_log  /www/wwwlogs/dealerpc-new.cn2de.com_purge_cache.log;
    }
    
    location ^~ /login_api {
        proxy_pass  http://login.xxx.com/api;
        proxy_set_header Host login.xxx.com; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        sub_filter "login_api" "";
        sub_filter_once on;
        add_header Cache-Control no-cache;
    }
    location ^~ /dealer_api {
        proxy_pass  http://dealer.xxx.com/api;
        proxy_set_header Host dealer.xxx.com; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        sub_filter "dealer_api" "";
        sub_filter_once on;
        add_header Cache-Control no-cache;
    }
    location ^~ /pps_api {
        proxy_pass  http://ccc.xxx.com/;
        proxy_set_header Host ccc.xxx.com; 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        sub_filter "pps_api" "";
        sub_filter_once on;
        add_header Cache-Control no-cache;
    }
    #引用反向代理规则,注释后配置的反向代理将无效
    #include /www/server/panel/vhost/nginx/proxy/123.xxx.com/*.conf;

    include enable-php-00.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/xxx.123.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log /dev/null;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log /dev/null;
    }
    access_log  /www/wwwlogs/123.xxx.com.log;
    error_log  /www/wwwlogs/123.xxx.error.log;
}

 

posted @ 2021-06-10 11:30  无聊的蚂蚁  阅读(97)  评论(0编辑  收藏  举报