nginx 配置文件

179 阅读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 80;
        server_name  jsnh.xyz;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        
        #前端网站及静态资源服务器部署配置
        #正常网站
        location / {
            alias /var/local/webfile/like/dist/;
            index index.html index.htm;
        }
        #vue网站
        location /live {
            alias /var/local/webfile/live/dist/;
            index index.html;
            try_files $uri $uri/ /live/index.html;
        }
        #静态资源配置
        location ^~ /staticfile/ {
            alias /var/local/staticfile/;
            autoindex on;
        }
        
        error_page 404 /404.html;
        location = /404.html {
        }

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

        #配置ssl证书
        listen 443 ssl; # managed by Certbot 

        #ssl_certificate /etc/letsencrypt/live/jsnh.xyz/fullchain.pem; # managed by Certbot
        #ssl_certificate_key /etc/letsencrypt/live/jsnh.xyz/privkey.pem; # managed by Certbot
        #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

        #阿里云证书给出的配置
        ssl_certificate cert/4902667_www.jsnh.xyz.pem;  #将domain name.pem替换成您证书的文件名称。
        ssl_certificate_key cert/4902667_www.jsnh.xyz.key; #将domain name.key替换成您证书的密钥文件名称。
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
        ssl_prefer_server_ciphers on;
    }
    server {
        rewrite ^(.*)$ https://$host$1 permanent; #将所有HTTP请求通过rewrite重定向到HTTPS。
    }
}