nginx redirect domain config

Nhan Cao
Jul 21, 2023
  • DNS service (Cloudflare): New A record to your server IP
  • SSH to server new virtual domain for redirecting.

Note: Change to your domain

# Create domain config
sudo -s
cat << 'EOF' > /etc/nginx/sites-available/
server {
listen 80;
listen [::]:80;

rewrite ^/(.*)$ permanent;

# Register domain
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo nginx -t
sudo service nginx reload

# Setup ssl
sudo certbot --nginx