404 Not Found error when loading the ulr of the second virtual block. What I am doing wrong?

March 7, 2015 7.1k views
DNS WordPress Nginx DigitalOcean PHP Ubuntu

I followed this tutorial to configure the server for running 2 Wordpress installations:

I have configure it with nginx, hhvm, ubuntu 14.04 and mysql. All was running smooth with the first Wordpress single installation.

After that, I tried to set up a second virtual block to migrate there my multisite with subdomains and there is where the trouble started.

I imported the database with the same database name and user than in the previous hosting (Hostgator), and copied the whole wordpress installation into a new folder at var/www. But I get the "404 Not Found nginx/1.6.2" screen.

What can be wrong?

My server block for the new configuration is:

server {
server_name *;
root /var/www/thecrazytravel;
access_log /var/log/nginx/;
error_log /var/log/nginx/;
include global/common.conf;
include global/wordpress.conf;
include hhvm.conf;

It is enabled, the same than the first block.

I changed the DNS in my domain to point to digitalocean's nameservers but I reverted it after noticing the error. I am testing now pointing from my computer to digitalocean server with my local host file (just in case you check it out and it works).

My DNS configuration on Digitalocean is:

I tried as well with the wild card (*) as CNAME but it didn't make any difference.

Is it something wrong on the nginx configuration? Or a permissions problem?

I assigned var/www/thecrazytavel to the same user than var/www/workraw (the other block) and tried with the same permits and nothing changed.

1 Answer

I solved it. I still have to polish it, but it is working. I just rewrote most of it instead of using the system of the tutorial I followed.

My code at the moment is:

server {
        ##DM - uncomment following line for domain mapping
        #listen 80 default_server;
        server_name * ;
        ##DM - uncomment following line for domain mapping
        #server_name_in_redirect off;

        access_log   /var/log/nginx/;
        error_log    /var/log/nginx/;

        root /var/www/thecrazytravel;
        index index.php index.html index.htm;
        include hhvm.conf;

# PLUGINS : Enable Rewrite Rules for Yoast SEO SiteMap
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

# Rewrite rules for WordPress Multi-site.
rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1;
if (!-e $request_filename)
rewrite ^.+?/?(/wp-.*) $1 last;
rewrite ^(.+)$ /index.php;

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

        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
    # ENABLE : Enable PHP, listen fpm sock
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;

        location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                access_log off; log_not_found off; expires 30d;

        location = /robots.txt { access_log off; log_not_found off; }
        location ~ /\. { deny  all; access_log off; log_not_found off; }

It could be improved, but it is running now. I hope it helps somebody out there with the same problem.

Have another answer? Share your knowledge.