0

Here is https://site.io, it's based on Wordpress. It is located in /var/www/site.io.

I need to add https://site.io/guides and put a fresh Wordpress engine there.

I've added this location to site.io nginx config:

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;
            }
    }

I've entered https://site.io/guides and Wordpress installation starts successfully. BUT https://site.io/guides/wp-admin/css/forms.min.css and other css and JS - don't work - 404 status.

forms.min.css exists at /var/www/guides/wp-admin/css/forms.min.css

So it seems that Nginx cannot access the file. What I did wrong?

Here is the full server block content:

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;
    }
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
Humanoit
  • 1
  • 1

1 Answers1

0

The problem is that your regular expression block is used when the file extension is .css.

To prevent usage of this block, use location ^~ /guides.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63