Report this

What is the reason for this report?

How to confingure nginx for domain and subdomain on AWS with ubuntu

Posted on November 8, 2017

I want to configure nginx for domain as well as sub domain on ubuntu as follows

mysite.in pointing to website demo.mysite.in pointing to demo project uat.mysite.in pointing to test project

My nginx conf looks like:

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;

    server_name mysite.in;
    location / {
            root /home/amita/Website/website-v1;
            try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;

    }

}

server { listen 8087; listen [::]:8087 default_server ipv6only=on;

    server_name demo.mysite.in;

    location / {

            root /home/amita/Project/frontend/demo/project/dist;
            try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
    }

}

server { listen 8088; listen [::]:8088 default_server ipv6only=on;

    server_name test.mysite.in;

    location / {

            root /home/amita/Project/frontend/test/project/dist;
            try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
    }

}

mysite.in , demo.mysite.in, test.mysite.in all shows up webiste.

I am unable to rectify mistake. Please help !!



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!

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.

Hello,

I have a subdomain setup but I’d do it all in DNS.

  1. server_name domain.com;
  2. server_name test.domain.com;
  3. server_name testing.domain.com

For domain.com I would insert an A DNS record with server IP. For the subdomains, I would create A records to the AWS server IP.

For an example of a nginx config file, this is how I’d do it. You should create a file like this on each server a domain or subdomain is pointing to. For example if domain.com is pointing to server1 and test.domain.com is pointing to server2, a nginx config file will need to exist on server1 and server2.

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name domain.com www.domain.com;
root /path/to/web/files;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
}

It’s really more of a PHP configuration that I use on my WordPress setup, but it should point you in the right direction.

Thanks.

Hello,

I set my subdomains up in different files. One domain per file to keep things simple. All you really need to do is change the server name as you said. Then you should enable your new Nginx site configs and restart Nginx. This article should help you get up and running.

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Hope it helps.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.