nginx配置

nginx 配置,包含指定域名跳转、手机访问识别、域名判断代理、日志配置


# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /home/logs/nginx/error.log info;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                 '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    log_format  acc  '$time_local|$remote_addr|$remote_user|"$request"|'
                     '$status|$body_bytes_sent|"$http_referer"|'
                     '"$http_user_agent"|"$http_x_forwarded_for"|$request_time|$upstream_response_time|$proxy_add_x_forwarded_for';
    access_log  /home/logs/nginx/access.log  acc;
    
    server_tokens       off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type text/html;  
    charset UTF-8;
   
    gzip on;  
    gzip_disable "msie6";  
    gzip_proxied any;  
    gzip_min_length 1000;  
    gzip_comp_level 6;  
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;  
    open_file_cache max=100000 inactive=20s;  
    open_file_cache_valid 30s;  
    open_file_cache_min_uses 2;  
    open_file_cache_errors on;

    fastcgi_intercept_errors on; 

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  www.xxx.com xxx.com;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
       
        if ($host = 'xxx.com' ) {
                rewrite    ^/(.*)$    http://www.xxx.com/$1    permanent;
        } 
        
       location /swallow {
                index index.htm index.html index.jsp;
                proxy_set_header Host $host:$server_port;
               # proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $remote_addr;
               proxy_pass http://127.0.0.1:8080;

        }

        location /pay {
                index index.htm index.html index.jsp;
                proxy_set_header Host $host:$server_port;
               # proxy_set_header        Host $host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $remote_addr;
               proxy_pass http://10.104.2.22;

        }
         
        location / {
                #手机访问跳转触屏版
                if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" )

    {

    
       rewrite    ^/(.*)$    http://www.xxx.com/swallow/wap    permanent;

    }                



                index index.htm index.html index.jsp;
                proxy_set_header        Host $host:$server_port;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $remote_addr;
                client_max_body_size    128m;
               if ($host = "aaa.xxx.com") {
                  proxy_pass http://10.104.2.22:8245;
               }
               if ($host = "bbb.xxx.com") {
                  proxy_pass http://10.104.2.22:8145;
               }
               if ($host = "www.xxx.com") {
                  proxy_pass http://10.104.2.22:8045;
               }

               error_page 404 = /404.html;
               error_page 500 502 503 504 = /50x.html;
        }

    }
}


你可能感兴趣的:(nginx,nginx,域名,手机)