1

我正在将我的 nginx 服务器设置为尽可能高效。从登陆页面开始。我决定使用 gzip_static 指令,它工作得很好,将我的 14kb index.html 预压缩到 3kb,并在调用 site.com/index.html 时提供服务。

但问题是当调用 site.com/nginx 返回 403 时(我将其设置为一直返回 403,以防止扫描仪试图找到他们不应该找到的东西,所以这基本上是 404。)

默认情况下,如何获取位置 / 以提供预压缩的 index.html?

server {
    server_name mxgaming.com;
    return 301 $scheme://www.mxgaming.com$request_uri;
}
server {
    listen 80;
    #listen 443 ssl;
    server_name www.mxgaming.com;
    root C:\\WebServer\\nginx\\www\\www.mxgaming.com;
    index index.html index.htm index.php;
    charset utf-8;
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    access_log off;
    error_log  C:\\WebServer\\nginx\\logs\\www.mxgaming.com-error.log error;
    sendfile off;
    client_max_body_size 100m;
    gzip_static on;
    gzip off;
    gzip_min_length 1024;
    gzip_proxied    any;
    gzip_http_version  1.1;
    gzip_comp_level    4;
    gzip_vary          on;
    gzip_types text/xml text/javascript application/atom+xml application/javascript application/json application/rss+xml application/xml+rss application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-   manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component;
    server_tokens off;
    location / {
        try_files $uri $uri/ /index.html;
    }
    location ~* /teamspeak/? {
        try_files $uri $uri/ /teamspeak.html;
    }
    location /teamspeakfull(?:/|) {
        try_files $uri $uri/ /teamspeakfull.html;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9123;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 60;
        fastcgi_read_timeout 60;
    }
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|woff|ogv|webm|htc)$ {
        expires 1y;
        access_log off;
        add_header Cache-Control "public";
    }
    location ~* \.(css|js)$ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
        try_files $uri $uri/ /assets/$1/$uri;
    }
    location ~ /\.ht {
        deny all;
    }
}

同样,只要您直接调用它们,调用和 .html、.js .css 就可以工作,但只是 / 没有。

4

0 回答 0