天天看点

nginx配置示例

例1:

# 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 /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;

    default_type        application/octet-stream;

    # 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       8000 default_server;

        #listen       8.141.48.129:80 default_server;

        #server_name  _;

        #root         /usr/share/nginx/html;

       location /api {

          proxy_pass http://8.141.48.129:1200/;

       }

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        location / {

            root   /usr/local/apache-tomcat-8.5.33/webapps/dist;

            index  index.html index.htm;

        }

        error_page 404 /404.html;

        location = /404.html {

        }

        error_page 500 502 503 504 /50x.html;

        location = /50x.html {

        }

    }

# Settings for a TLS enabled server.

#

#    server {

#        listen       443 ssl http2 default_server;

#        listen       [::]:443 ssl http2 default_server;

#        server_name  _;

#        root         /usr/share/nginx/html;

#

#        ssl_certificate "/etc/pki/nginx/server.crt";

#        ssl_certificate_key "/etc/pki/nginx/private/server.key";

#        ssl_session_cache shared:SSL:1m;

#        ssl_session_timeout  10m;

#        ssl_ciphers HIGH:!aNULL:!MD5;

#        ssl_prefer_server_ciphers on;

#

#        # Load configuration files for the default server block.

#        include /etc/nginx/default.d/*.conf;

#

#        location / {

#        }

#

#        error_page 404 /404.html;

#        location = /404.html {

#        }

#

#        error_page 500 502 503 504 /50x.html;

#        location = /50x.html {

#        }

#    }

}

例2:

# 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 /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;

    default_type        application/octet-stream;

    # 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;

       #rewrite ^/(.*)$ https://172.20.10.29:443/$1 permanent;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

       location /api {

          proxy_pass http://172.20.10.29:8888/api/v1/;

       }

    location ^~ /rest/qf {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.41:8080;

        }

    }

    location ^~ /rest/dataReport {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /rest/monitoring {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /common {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.2:9090;

        }

    }

        location / {

            root   /usr/local/milun/daping/distt;

            index  index.html index.htm;

        }

        error_page 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

server {

        listen       9091 ;

        server_name  172.20.10.29;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        #location /api {

          #  proxy_pass http://172.20.10.29:8081/api/v1/;

       # }

    location ^~ /rest/qf {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.41:8080;

        }

    }

    location ^~ /rest/dataReport {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /rest/monitoring {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /common {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.2:9091;

        }

    }

        location / {

            root   /usr/local/milun/daping/caslogin;

            index  index.html index.htm;

        }

        error_page 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

server {

        listen       9092 ;

        server_name  172.20.10.29;

        # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        #location /api {

          #  proxy_pass http://172.20.10.29:8081/api/v1/;

       # }

    location ^~ /rest/qf {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.41:8080;

        }

    }

    location ^~ /rest/dataReport {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /rest/monitoring {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        proxy_hide_header Access-Control-Allow-Origin;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.43:80;

        }

    }

    location ^~ /common {

        proxy_set_header Origin '';

        add_header Access-Control-Allow-Credentials true;

        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        add_header Access-Control-Allow-Methods POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH;

        add_header Access-Control-Allow-Origin $http_origin;

        add_header Access-Control-Expose-Headers $http_access_control_request_headers;

        if ($request_method = 'OPTIONS') {

            return 204;

        }

        if ($request_method != 'OPTIONS'){

            proxy_pass http://172.20.10.2:9091;

        }

    }

        location / {

            root   /usr/local/milun/dict/dist;

            index  index.html index.htm;

        }

        error_page 404 /404.html;

            location = /40x.html {

        }

        error_page 500 502 503 504 /50x.html;

            location = /50x.html {

        }

    }

    server {

        listen      9093;

        server_name  172.20.10.29;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /usr/local/milun/xiazhongrui/dist;

            index  index.html index.htm;

        }

        #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   html;

        }

    }

# Settings for a TLS enabled server.

#

#    server {

#        listen       443 ssl http2 default_server;

#        listen       [::]:443 ssl http2 default_server;

#        server_name  _;

#        root         /usr/share/nginx/html;

#

#        ssl_certificate "/etc/pki/nginx/server.crt";

#        ssl_certificate_key "/etc/pki/nginx/private/server.key";

#        ssl_session_cache shared:SSL:1m;

#        ssl_session_timeout  10m;

#        ssl_ciphers HIGH:!aNULL:!MD5;

#        ssl_prefer_server_ciphers on;

#

#        # Load configuration files for the default server block.

#        include /etc/nginx/default.d/*.conf;

#

#        location / {

#        }

#

#        error_page 404 /404.html;

#            location = /40x.html {

#        }

#

#        error_page 500 502 503 504 /50x.html;

#            location = /50x.html {

#        }

#    }

}

stream{

  log_format basic '$remote_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received' '$session_time';

  upstream impala { #impala daemon

    least_conn; #路由策略:least_conn:最少连接

    server 172.20.10.2:21000;

    server 172.20.10.3:21000;

    server 172.20.10.4:21000;

    server 172.20.10.5:21000;

    server 172.20.10.6:21000;

    server 172.20.10.7:21000;

    server 172.20.10.8:21000;

    server 172.20.10.9:21000;

  }

  upstream impala-jdbc {

    least_conn;

    server 172.20.10.2:21050;

    server 172.20.10.3:21050;

    server 172.20.10.4:21050;

    server 172.20.10.5:21050;

    server 172.20.10.6:21050;

    server 172.20.10.7:21050;

    server 172.20.10.8:21050;

    server 172.20.10.9:21050;

  }

  server{ #impala 负载均衡

    listen 21000;

    proxy_pass impala;

  }

  server{ #impala jdbc 负载均衡

    listen 21050;

    proxy_pass impala-jdbc;

  }

}

继续阅读