Skip to main content

Vhost for WordPress in sub folder

This the the vhost snippet which can be placed in your existing vhost for WordPress to make it load properly from a sub folder.

location /wp2/ {
    try_files $uri $uri/ /wp2/index.php?$args;
    index index.htm index.php;
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_read_timeout 3600;
    fastcgi_send_timeout 3600;
    fastcgi_param HTTPS "on";
    fastcgi_param SERVER_PORT 443;
    fastcgi_pass 127.0.0.1:{{php_fpm_port}};
    fastcgi_param PHP_VALUE "{{php_settings}}";
    
    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map)$ {
    add_header Access-Control-Allow-Origin "*";
    expires max;
    access_log off;
  }
  }

Please paste this in the 80/443 Server block. If you wish to host more sites in a sub folder then create similar block for each sub folder site.