Nginx 中的位置未按预期工作

Nginx 中的位置未按预期工作

这是https://site.io,它基于 Wordpress。它位于 /var/www/site.io。

我需要补充https://site.io/guides并在那里放置一个新的 Wordpress 引擎。

我已将此位置添加到 site.io nginx 配置中:

location /guides {

            alias /var/www/guides;

            try_files $uri $uri/ index.php?$args;

            location ~ \.php$ {
                    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
                    fastcgi_split_path_info ^(.+\.php)(/.*)$;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $request_filename;
            }
    }

我已经输入https://site.io/guidesWordpress 安装成功启动。但是https://site.io/guides/wp-admin/css/forms.min.css和其他 css 和 JS - 不起作用 - 404 状态。

forms.min.css 位于 /var/www/guides/wp-admin/css/forms.min.css

看来 Nginx 无法访问该文件。我做错了什么?

以下是完整的服务器块内容:

server {
    listen         80 default_server;
    listen         [::]:80 default_server;

    server_name    site.io www.site.io;
    root           /var/www/site.io/;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl on;
    ssl_certificate /etc/ssl/certs/site/cert.pem;
    ssl_certificate_key /etc/ssl/private/site/key.pem;
    ssl_client_certificate /etc/ssl/certs/origin-pull-ca.pem;
    ssl_verify_client on;

    rewrite ^/blog/(.+\.(gif|jpg|jpeg|png))$ https://site.io/$1 redirect;

    index index.php;

    location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
            fastcgi_cache_bypass $no_cache;
            fastcgi_no_cache $no_cache;


            location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            }
    }
    
    location /guides {
            alias /var/www/guides;
            try_files $uri $uri/ index.php?$args;

            location ~ \.php$ {
                    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
                    fastcgi_split_path_info ^(.+\.php)(/.*)$;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $request_filename;
            }
    }

    access_log /var/log/nginx/site.io.access.log;
    error_log /var/log/nginx/site.io.error.log;

    gzip on;
    gzip_vary on;
    gzip_min_length 1400;
    gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;

    location ~* ^.+\.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|mp3|wav|xml|zip|tar|gz|rar|7z|swf|html|htm|ttf|otf|woff|svg|eot|ico|css|js|webp|map)$ {
                access_log off;
                expires 7d;
                break;
        }

    location /apple-app-site-association {
        default_type application/pkcs7-mime;
            index apple-app-site-association;
            try_files $uri $uri/  /apple-app-site-association$is_args$args;
    }
}

答案1

问题是,当文件扩展名是 时,使用了正则表达式块.css

为了防止使用此块,请使用location ^~ /guides

相关内容