nginx一个域名搞定后台接口+vue静态页面配置

子域名 www.xxx.com.conf:

server
    {
        listen 80;
        listen 443 ssl http2;
        server_name admin.xxx.com;
        #index index.html index.htm index.php default.html default.htm default.php;
        #root  /data/wwwroot/admin.xxx.com;

        ssl_certificate /etc/nginx/cert/2021.crt;
        ssl_certificate_key /etc/nginx/cert/2021.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;

        location /h1 {
                alias /data/wwwroot/admin.xxx.com/h1/;
                index index.html;
                try_files $uri $uri/ /index.html;
        }
        location /h2 {
                    alias /data/wwwroot/admin.xxx.com/h2/;
                index index.html;
                try_files $uri $uri/ /index.html;
                    }

        location / {
                root /data/wwwroot/admin.xxx.com;
                index index.html;
                try_files $uri $uri/ /index.html;
        }
        
        location /api
        {
                proxy_pass http://localhost:8888;
                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;
                proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
                proxy_max_temp_file_size 0;
                proxy_connect_timeout 90;
                proxy_send_timeout 90;
                proxy_read_timeout 90;
                proxy_buffer_size 4k;
                proxy_buffers 4 32k;
                proxy_busy_buffers_size 64k;
                proxy_temp_file_write_size 64k;
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE,OPTIONS';
                add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

                if ($request_method = 'OPTIONS') {
                    return 204;
                    }
        }
        
        
        location  ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$
        {
           root /data/wwwroot/admin.xxx.com/;
           proxy_temp_path /data/wwwroot/admin.xxx.com/;
        }


        #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        #{
            #expires      30d;
        #}

        #location ~ .*\.(js|css)?$
         #{
         #   expires      12h;
         #}

        #location ~ /.well-known {
           # allow all;
       # }

        #location ~ /\.
        #{
         #   deny all;
        #}
        
      #location / {
       #try_files $uri $uri/ /index.html;
      #}

        access_log  /data/wwwlogs/admin.xxx.com.log;
    }

主配置 nginx.conf:


worker_processes 8;
worker_cpu_affinity auto;

error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }

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

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 20m;

        sendfile on;
        sendfile_max_chunk 512k;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server;

        server_name _;
        index index.html index.htm index.php;

rewrite ^(.*)$ https://$host$1 permanent;
    



        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /data/wwwlogs/access.log;
    }
include conf.d/*.conf;
}

你可能感兴趣的:(nginx一个域名搞定后台接口+vue静态页面配置)