What I want to do ?
I have two application on local ports and I want to access them like that :
- maindomain.com -> node.js app
- sub.maindomain.com -> .net core app
My DNS config
- maindomain.com (A Record) 11.111.11.111
- sub.maindomain.com (A Record) 11.111.11.111
Nginx config
> /etc/nginx/sites-enabled/maindomain.com (linked from ./sites-available/)
upstream node_app{
# node.js running
server 127.0.0.1:8000;
}
server{
listen 80;
server_name www.maindomain.com maindomain.com;
#Redirige toutes les requêtes http vers https
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
location / {
include proxy_params;
proxy_pass http://node_app;
}
}
> /etc/nginx/sites-enabled/sub.maindomain.com (linked from /sites-available/)
upstream core_api{
# Asp.net core API running in background
server 127.0.0.1:5000;
}
server{
listen 80;
server_name www.sub.maindomain.com sub.maindomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
location / {
include proxy_params;
proxy_pass http://core_api;
}
}
Result :
After that, I have restarted my nginx service.
Requests on sub.maindomain.com just redirect on maindomain.com.
What did I missed ?
I have two application on local ports and I want to access them like that :
- maindomain.com -> node.js app
- sub.maindomain.com -> .net core app
My DNS config
- maindomain.com (A Record) 11.111.11.111
- sub.maindomain.com (A Record) 11.111.11.111
Nginx config
> /etc/nginx/sites-enabled/maindomain.com (linked from ./sites-available/)
upstream node_app{
# node.js running
server 127.0.0.1:8000;
}
server{
listen 80;
server_name www.maindomain.com maindomain.com;
#Redirige toutes les requêtes http vers https
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
location / {
include proxy_params;
proxy_pass http://node_app;
}
}
> /etc/nginx/sites-enabled/sub.maindomain.com (linked from /sites-available/)
upstream core_api{
# Asp.net core API running in background
server 127.0.0.1:5000;
}
server{
listen 80;
server_name www.sub.maindomain.com sub.maindomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
location / {
include proxy_params;
proxy_pass http://core_api;
}
}
Result :
After that, I have restarted my nginx service.
Requests on sub.maindomain.com just redirect on maindomain.com.
What did I missed ?