Help adding multiple WP sites on LEMP

April 11, 2015 866 views
WordPress Nginx

Hi have my brand new LEMP server up and running. So far I have configured 1 website, which is running without problems, configuring the DNS of my domain in godaddy and everything looks good.

Now, I've tried to add another website, doing exactly the same as I did for my first WP website, and I can't make it run.

Whats happening is, when I go on the browser to domain1.com or www.domain1.com, it works well, it goes to the website path that I configured on the server block. But when I go to domain2.com, it opens the website of the domain1.com but without changing the domain on the browser, I mean, on the browser you still can see the domain2.com address, but it loads the site from the domain1.com.

And when I go to www.domain2.com, it loads the main screen of the nginx server.

But when put on the brower the IP of my server, it loads the content of the domain1.com.

I tried everything that I could, but nothing seems to work...any help?

I have a server block with this configuration, in /etc/nginx/sites-available/ and enabled /etc/nginx/sites-enabled/:

server {
    server_name www.domain1.com
    root /var/www/html/web/web1;
    access_log /var/log/nginx/www.domain1.com.access.log;
    error_log /var/log/nginx/www.domain1.com.error.log;
    include global/common.conf;
    include global/wordpress.conf;
}
server {
    server_name www.domain2.com;
    root /var/www/html/secure/web2;
    access_log /var/log/nginx/www.domain2.com.access.log;
    error_log /var/log/nginx/www.domain2.com.error.log;
    include global/common.conf;
    include global/wordpress.conf;
}

I have common.conf file in /etc/nginx/global with this:

# Global configuration file.
# ESSENTIAL : Configure Nginx Listening Port
listen 80;
# ESSENTIAL : Default file to serve. If the first file isn't found, 
index index.php index.html index.htm;
# ESSENTIAL : no favicon logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}
# ESSENTIAL : robots.txt
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
# ESSENTIAL : Configure 404 Pages
error_page 404 /404.html;
# ESSENTIAL : Configure 50x Pages
error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }
# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /\. {
    deny all;
}
# PERFORMANCE : Set expires headers for static files and turn off logging.
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;
}

And another file in common for the wordpress sites:

# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the appended query string intact
location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}
# REQUIREMENTS : Enable PHP Support
location ~ \.php$ {
    # SECURITY : Zero day Exploit Protection
    try_files $uri =404;
    # ENABLE : Enable PHP, listen fpm sock
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}
# 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;
1 comment
2 Answers

@ -> myserverip
admin -> myserverip

HOST
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

POINTS TO
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Thats the same configuration that I have for my domain that already works (domain1.com in my example)

I just configured the DNS in my domain provider (godaddy). Should I do anything else related to DNS on my server?

Have another answer? Share your knowledge.