I'm new to nginx
server.
I need to run 3 different code bases based on domains and sub domains in ubuntu 16.X server.
domain.com
sub1.domain.com
sub2.domain.com
In my /etc/nginx/sites-available
folder, I have created 3 files
domain.conf
domain1.conf
domain2.conf
Here is the code in each file
domain.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name domain.com;
root /var/www/html;
index index.html;
location / {
if (!-e $request_filename){
rewrite ^/([^\.]+)$ /$1.html break;
}
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.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
}
domain1.conf
server {
listen 80;
listen [::]:80;
server_name sub1.domain.com;
root /var/www/app/angular_app/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
domain2.conf
server {
listen 80;
listen [::]:80;
server_name sub2.domain.com;
root /var/www/supportapp;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
domain.com
and sub1.domain.com
are working perfectly with http
and https
.
But when I type in http://sub2.domain.com
, it is taking me to domain.com
index.html
file and when I type in https://sub2.domain.com
, it is taking me to sub1.domain.com
index.html
file
nginx -t
doesn't show any errors.
What could be the problem? How do I solve it?