我所有在线项目的Nginx配置内容

2022-04-11 11:41:34 浏览数 (1)

有几个小伙伴想看看我的Nginx是怎么配置的,我这里放出来吧。

其实没太多内容,都是基本的配置:

1、域名的代理(正向/反向);

2、IP地址获取;

3、SingleR Header配置;

4、前后端配置;

5、域名配置;

6、HTTPS配置;

7、负载配置;

代码语言:javascript复制

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
  server_names_hash_bucket_size 64; 

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  600;
    proxy_read_timeout 600; 
    proxy_send_timeout 600; 

    #gzip  on;
  upstream mysvr { 
      server 192.168.10.121:3333;
      server 192.168.10.122:3333;
    }
   server {
        ....
        location  ~*^. $ {         
           proxy_pass  http://mysvr;  #请求转向mysvr 定义的服务器列表         
        }
   }
######################################################################

    server {
        listen       80;
        server_name  www.neters.club;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
              root   C:codeCodeNetershome;
              index  index.html index.htm;
        }
    }


    server {
        listen       80;
        server_name  neters.club;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
              root   C:codeCodeNetershome;
              index  index.html index.htm;
        }
    }

    server {
        listen       80;
        server_name  ids.neters.club;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
              root   html;
              proxy_pass   http://localhost:5004;
              index  index.html index.htm;
        }

    }
  server {
        listen         443 ssl;
        server_name  ids.neters.club;  #网站域名,和80端口保持一致
        ssl             on;
        ssl_certificate 1_ids.neters.club_bundle.crt;       #证书公钥
        ssl_certificate_key  2_ids.neters.club.key;  #证书私钥

        #ssl_certificate ids.neters.club.crt;  
        #ssl_certificate_key ids.neters.club.rsa; 
 
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
        ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!3DES:!aNULL:!eNULL;
        ssl_prefer_server_ciphers  on;
        location / {
            proxy_pass http://ids.neters.club;
            proxy_redirect  off;     
            proxy_set_header        Host    $http_host;     
            proxy_set_header        X-Real-IP       $remote_addr;     
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;     
            proxy_set_header   Cookie $http_cookie;
            #proxy_cookie_path
            chunked_transfer_encoding       off;         
        }

    }
    server {
        listen       80;
        server_name  apk.neters.club;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
          root   html;
          proxy_pass   http://localhost:8081;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_cache_bypass $http_upgrade;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          index  index.html index.htm;
        }

        location /.doc/ {
          proxy_pass http://docs.neters.club/;
        }
    }

    server {
        listen       80;
        server_name  docs.neters.club;

        location / {
            root   C:codeCodeBlog.Core.docscontents.vuepressdist;
            index  index.html index.htm;
        }
    }

    server {
        listen       80;
        server_name  vueadmin.neters.club;

        location / {
            try_files $uri $uri/ /index.html;
            root   C:codeCodeBlog.Admindistis;
            index  index.html index.htm;
        }

        location /api/ {
              rewrite  ^. apb/?(.*)$ /$1 break;
              include  uwsgi_params;
              proxy_pass http://localhost:8081;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              #proxy_set_header Connection "upgrade";
              #proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
        location /api2/ {
              rewrite  ^. apb/?(.*)$ /$1 break;
              include  uwsgi_params;
              proxy_pass http://localhost:8081;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "upgrade";
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /.doc/ {
          proxy_pass http://docsadmin.neters.club/;
        }


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

    server {
        listen       80;
        server_name  docsadmin.neters.club;

        location / {
            root   C:codeCodeBlog.Admin.doccontents.vuepressdist;
            index  index.html index.htm;
        }
    }

    

    server {
        listen       80;
        server_name  ddd.neters.club;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
              root   html;
              proxy_pass   http://localhost:4773;
              index  index.html index.htm;
        }
    }

  


    server {
        listen       80;
        server_name  vueblog.neters.club;

        location / {
            try_files $uri $uri/ /index.html;
            root   C:codeCodeBlog.Vuedist;
            index  index.html index.htm;
        }


        location /api {
            rewrite  ^. apb/?(.*)$ /$1 break;
            include  uwsgi_params;
            proxy_pass   http://localhost:8081; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }


        location /images { 
            include  uwsgi_params;
            proxy_pass   http://localhost:8081; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

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


    server {
        listen       80;
        server_name  tibug.neters.club;
        
        location / {
            try_files $uri $uri/ /index.html;
            root   C:codeCodeNuxt.tBugdist;
            index  index.html index.htm;
        }


        location /api {
            rewrite  ^. apb/?(.*)$ /$1 break;
            include  uwsgi_params;
            proxy_pass   http://localhost:8081; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }


        location /images { 
            include  uwsgi_params;
            proxy_pass   http://localhost:8081; 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

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

0 人点赞