Skip to content

Nginx 示例配置

/etc/nginx/nginx.conf

shell
# user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    # 默认 body 大小限制为 1M,根本不够用
    client_max_body_size 1024m;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;

    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types text/plain text/css application/xml application/javascript application/x-javascript text/javascript;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

    # 一律转发 http 端口到 https,以达到同时支持 http 和 https 访问
    server {
        listen 80;
        server_name *.aday.fun;
        rewrite ^(.*)$ https://$host$1 permanent;
    }

    server {
        listen       443 ssl;
        server_name  home.aday.fun;
        ssl_certificate /etc/nginx/ssl/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/*.aday.fun.key;

        location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
            # vue 项目这样配置
            #try_files $uri $uri/ /index.html;
            # vitepress 项目这样配置
            try_files $uri $uri.html $uri/ =404;

            error_page 404 /404.html;
            error_page 403 /404.html;
        }
    }

    server {
        listen      443 ssl;
        server_name vitality.aday.fun;
        ssl_certificate /etc/nginx/ssl/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/*.aday.fun.key;

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8080/;
        }
    }

    server {
        listen      443 ssl;
        server_name jenkins.aday.fun;
        ssl_certificate /etc/nginx/ssl/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/*.aday.fun.key;

        location / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8090/;
        }
    }
}

docker 下 nginx 配置

可参考:Docker 安装 Nginx