Site icon NgDeveloper

Route Godaddy Subdomain to AWS EC2 Nginx Config

This post contains the configurations for the godaddy subdomain to route to aws ec2 with nginx as web server and some configs added to take care of the direct refresh on the end urls.

In Godaddy, create the subdomain and redirect that to AWS EC2 Machine IP (Elastic IP) as A record like below,

This is the AWS EC2 installed nginx config for the subdomain setup. This file mostly presents in the /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        server_name  dashboard.ngdeveloper.com;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        error_page 404 /404.html;
        location = /404.html {
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/dashboard.ngdeveloper.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dashboard.ngdeveloper.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
                location / {
                     try_files $uri $uri/ /index.html;
                }
      }

       server {
        listen 80;
        server_name dashboard.ngdeveloper.com;
        return 301 https://dashboard.ngdeveloper.com$request_uri;
       }


        # dashboard.ngdeveloper.com - 443
      server {
                listen 443 ssl;
                server_name dashboard.ngdeveloper.com;
    ssl_certificate /etc/letsencrypt/live/dashboard.ngdeveloper.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dashboard.ngdeveloper.com/privkey.pem; # managed by Certbot
                return 301 https://dashboard.ngdeveloper.com$request_uri;

        }
}
Exit mobile version