By akash
Hi there,
I done the one click Ghost install and this works fine.
Then I decided to move my blog: FROM: blog.club.in (ccTLD) TO: blog.club.com (gTLD)
Basically from a ccTLD to a gTLD.
How do I setup a 301 with Nginx to redirect all http and https traffic from my ccTLD to the .com?
Thanks!
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!
Heya,
Sure, here’s how you can set up a 301 redirect using Nginx for your case.
First, you should backup your existing Nginx configuration file:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
Next, open the Nginx configuration file in a text editor. I’ll use nano for this example:
sudo nano /etc/nginx/sites-available/default
Replace the existing server block for your ccTLD with a new one that includes a return directive to handle the redirect:
server {
listen 80;
listen [::]:80;
server_name blog.club.in;
return 301 $scheme://blog.club.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name blog.club.in;
ssl_certificate /etc/letsencrypt/live/blog.club.in/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.club.in/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
return 301 $scheme://blog.club.com$request_uri;
}
Replace blog.club.in with your ccTLD and replace blog.club.com with your gTLD. Also, make sure the paths to the SSL certificate and key files are correct.
This configuration listens for both HTTP (port 80) and HTTPS (port 443) requests to your ccTLD and redirects them to the equivalent URL on your gTLD using a 301 (permanent) redirect.
Save the file and exit the text editor.
Check your Nginx configuration for syntax errors:
sudo nginx -t
sudo service nginx restart
Now, any traffic to your ccTLD should be redirected to your gTLD.
Keep in mind that it’s recommended to backup your Nginx configuration file before making changes, and always check the configuration syntax before reloading Nginx.
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.