nginx implement switching and interfaces to access admin page by rules

Corporate environment:
18 years Guangxi Telecom customer's network environment, because the traffic is 10 apache big business machine, back office 2, 8, MySQL standby, redis standby interface to access.
Because nginx proxy to pick up 10 apache, nginx proxy configuration as the ports and only one interface to access and back office management is an interface, which is necessary to achieve a different time different url to access the host through nginx rule.
url interface to access:
1. Interface forms are * .php and then add some parameters
2. part of the interface is accessed through the directory, there are app directory, the directory has onemall
3. backstage access direct form of access is the domain name plus port
 
 
Directly on nginx configuration, wherein the interface data buffer to do, is not required in the background, arranged four by a location server to achieve
cat vhost.conf
proxy_redirect off;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_buffers 32 64k;
proxy_buffer_size 16k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
 
proxy_cache_use_stale  updating;
proxy_cache_lock  on;
proxy_cache_lock_timeout  3;
 
#proxy_temp_path /data/nxcache/temp;
proxy_cache_path /data/nxcache/cache1  levels=1:2 keys_zone=cache1:1024m  max_size=20g inactive=30m;
proxy_cache_path /data/nxcache/cache2  levels=1:2 keys_zone=cache2:1024m  max_size=30g inactive=1d;
 
upstream jiekou {
    server 90.77.4.3:5181 weight=1;
    server 90.77.4.4:5181 weight=1;
    server 90.77.4.5:5181 weight=1;
    server 90.77.4.6:5181 weight=1;
    server 90.77.4.7:5181 weight=1;
    server 90.77.4.8:5181 weight=1;
    server 90.77.4.9:5181 weight=1;
    server 90.77.4.10:5181 weight=1;
}
upstream as {
    server 90.77.4.1:5181;
}
 
server {
    listen                *:80;
    server_name          xxxxxxx.com;
    access_log           /data/nginxlogs/as_local_access/as_access.log main;
    error_log             /data/nginxlogs/error.log;
   #匹配app目录接口
    location ^~ /app/ {
        proxy_set_header Host $host;
        proxy_pass          http://jiekou;
        proxy_read_timeout  60;
        #proxy_cache cache1;
        #proxy_cache_key    $host$uri$is_args$args;
        ##proxy_cache_key    $uri;
        #proxy_cache_valid 200 206 304 5m;
        #proxy_cache_valid 404 1s;
        add_header  Nginx-Cache "$upstream_cache_status";
}
    #匹配onemall目录接口
    location ^~ /onemall/ {
        proxy_set_header Host $host;
        proxy_pass          http://jiekou;
        proxy_read_timeout  60;
        #proxy_cache cache1;
        #proxy_cache_key    $host$uri$is_args$args;
        ##proxy_cache_key    $uri;
        #proxy_cache_valid 200 206 304 5m;
        #proxy_cache_valid 404 1s;
        add_header  Nginx-Cache "$upstream_cache_status";
    }
    #匹配*.php文件接口
    location ~* \.(php)$ {
        proxy_set_header Host $host;
        proxy_pass          http://jiekou;
        proxy_read_timeout  60;
        #proxy_cache cache1;
        #proxy_cache_key    $host$uri$is_args$args;
        ##proxy_cache_key    $uri;
        #proxy_cache_valid 200 206 304 5m;
        #proxy_cache_valid 404 1s;
        add_header  Nginx-Cache "$upstream_cache_status";
    }
    #匹配访问后台管理页面
    location ~ / {
        proxy_set_header Host $host;
        proxy_pass          http://as;
        proxy_read_timeout  60;
        #proxy_cache cache1;
        #proxy_cache_key    $host$uri$is_args$args;
       # #proxy_cache_key    $uri;
        #proxy_cache_valid 200 206 304 1d;
        #proxy_cache_valid 404 1s;
        add_header  Nginx-Cache "$upstream_cache_status";
    }
}

 

Guess you like

Origin www.cnblogs.com/daboluoya/p/11579922.html