Question
Need help moving Wordpress site as 2nd domain on Ubuntu nginx
I’m having trouble moving a wordpress website to a new LEMP server. lets use “example.com” as the example. I successfully copied the PHP files and the database to the new server and temporarily set it up as “example.org” so the “live” example.com would keep functioning while I worked on the new server. I created a server block for it and example.org was working just fine.
Here is the partial server block code that was working with the .ORG site.
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.php index.html index.htm;
server_name example.org www.example.org;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
PLEASE NOTE: We already had a very busy production web site on the LEMP server at “email.example.com”, a sub-domain we use for our email campaigns. That site has been working very well for 6 months. It was using the DEFAULT server block and still is. Here is the code for that site.
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name email.example.com mailer.example.com;
try_files $uri $uri/ =404;
}
}
Since everything was working great with “email.example.com” the default site, and “example.org” the new site, I decided to point “example.com” to the IP address of the new LEMP server. I edited the Server block for the new site to reflect the server names “example.com www.example.com” as below. I included some redirects, which I hope are correct, so that “example.org” and “example.net” also, hopefully, resolve to “example.com”.
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.php index.html index.htm;
server_name example.com www.example.com;
rewrite ^/(.*)$ http://example.org/$1 permanent;
rewrite ^/(.*)$ http://example.net/$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
And YES I also changed the entries in the wp_options wordpress table for “siteurl” and “home” to “http://example.com”.
BUT now when I enter example.com or example.org or example.net into my browser the DEFAULT website *http://email.example.com * appears instead of the new site! But the URL displayed in the Browser is example.com. Right URL but Wrong website.
Please help if anyone can tell me what I may have done wrong.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×