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!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Here is how I would 301 Perm Redirect with Nginx - non-www to www and also added in your blog block.
# Redirect non-www to www
#
server {
server_name example.com;
listen 80;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
location / {
root /var/www/example.com/public_html/;
index index.html index.htm;
}
# 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;
}
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.