Nginx Practice (Part 2) - Common Configuration

1. Nginx proxy static directory configuration

server {

    listen       80;

    server_name public domain name;

 

    #charset koi8-r;

    access_log access log directory main;

 

 location / {

         root needs the static directory of the proxy;

         try_files $uri $uri/ @router;

         index index.html;

         expires -1;##Configure all resources not to be cached

     }

 

    location @router {

        rewrite ^.*$ /index.html last;

    }

 

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

2. Nginx proxy IP configuration

server {

    listen       80;

    server_name public domain name;

 

    #charset koi8-r;

    access_log access log directory main;

 

    location / {

        proxy_redirect          off;

        proxy_set_header        Host            $host;

        proxy_set_header        X-Real-IP       $remote_addr;

        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        client_max_body_size    64m;

        client_body_buffer_size 10M;

        proxy_buffers           32 4k;

        proxy_connect_timeout   3;

        proxy_send_timeout      30;

        proxy_read_timeout      30;

        #内网IP+端口

        proxy_pass http://代理的服务器IP地址:8080;##需要代理的app应用访问地址

    }

 

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

3.Nginx域名转发配置

如果存在新旧域名,旧域名还需要保留,那我们就需要进行相关的配置,访问旧域名就自动转发到新域名上去。两种实现方案如下:

方案一:域名解析的时候,直接配置,旧域名直接指向新域名;

方案二:添加Nginx配置

server {

    listen       80;

    server_name  旧域名;

 

    #charset koi8-r;

    access_log  访问日志目录  main;

 

    rewrite ^/(.*) http://新域名/$1 permanent;

 

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326182994&siteId=291194637