Hello all, I have a droplet setup with my domain example.com, my webserver is nginx, I have setup my server blocks in order to have my site in example.com and my blog with blog.example.com, everything was working well, I’am using a CNAME for WWW. and another CNAME for BLOG.
I noticed that I have duplicated content at google ayes because I serve the same site in my www domain and my non-www. I have read some tutorials to redirect all my non-www traffic to my www site.
When I made the changes, my surprise was that now my blog is served in example.com and in blog.example.com, I don’t know what im doing wrong,
My configs in sites-available are:
Main Site:
server{
listen 80;
listen [::]:80 default_server;
root /var/www/main/html;
index index.html index.php index.htm;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
location / {
try_files $uri $uri/ = 404;
}
}
Blog:
server {
listen 80;
server_name blog.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
Pretty basic configs that worked before the changes, have to say my blog is running under Ghost, I mantain the blog alive with “supervisord” in the past have used “forever” installed vía npm, I don’t think this is the problem but I think every detail helps.
My “main site” right now is only a “.html” file, as you can see in the config, the priority to serve files is “.html”
Thank you in advance to you all!
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
Here is how I would 301 Perm Redirect with Nginx - non-www to www and also added in your blog block.