-2

I have an nginx server with php5-fpm hosting 3 frameworks. 1 PHP framework, 2 wordpress.

All live in the /var/www folder, so for this purpose

  • /var/www/website - PHP framework
  • /var/www/blog - Wordpress
  • /var/www/blog2 Wordpress

When trying to access the blogs, all of the assets(css, images, etc...) don't work, they throw a 404. I can't access the wp-admin page as well since it results in an infinite redirect.

Here's the relevant information in the Nginx config file.

server{
    root /var/www/website;
    index index.html index.htm index.php;

    set $php_root /var/www/website;

    location /blog {
        set $php_root /var/www/blog;

        if(!-e $request_filename){
            rewrite ^(.+)$ /index.php last;
            break;
        }
    }

    location /blog2 {
        set $php_root /var/www/blog2;

        if(!-e $request_filename){
            rewrite ^(.+)$ /index.php last;
            break;
        }
    }

    location / {
        if(!-e $request_filename){
            rewrite ^(.+)$ /index.php last;
            break;
        }
    }

    location ~ \.php$ {
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
    }

}

Any and all help is appreciated.

1

The problem with your configuration is that you are only setting the paths to access the PHP files, and nginx still tries to access static resources via the directory specified in root directive.

alias is the directive that should be used when you want to serve some URI from a different directory.

This should be a proper configuration for your needs.

server {
    root /var/www/website;
    index index.html index.htm index.php;

    try_files $url $url/ /index.php;

    location /blog {
        alias /var/www/blog;
    }

    location /blog2 {
        alias /var/www/blog2;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.