静态网站的Nginx配置示例

2022-01-01#Nginx

一个简单的Nginx配置示例,开箱即用。

user  nginx;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include             mime.types;
    default_type        application/octet-stream;
    sendfile            on;
    keepalive_timeout   65;

    types {
        font/ttf ttf;
        font/otf otf;
        font/woff woff;
        font/woff2 woff2;
    }

    server {
        gzip on;
        gzip_types      text/plain application/xml application/json text/css application/javascript font/ttf font/otf font/woff font/woff2;
        gzip_disable    "MSIE [1-6]\.";
        gzip_vary       on;
        listen          80;
        server_name     localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            try_files $uri /index.html;
        }

        location ^~ /static/ {
            expires 30d;
            add_header Cache-Control "public, max-age=2592000";
            access_log off;  # Disable access log for static files
            root   /usr/share/nginx/html;
        }
    }
}

加载中...