I had a working configuration in nginx for just one of my websites, but I broke it when I tried to make it work with 2 different domains, one of which has 2 sub domains, all serving different sites or applications. To make matters harder on me, the domain running 2 apps is on a separate machine, and I am trying to proxy requests for that domain to the correct machine on my LAN. See below:
My NGINX config is a disaster, but is as follows:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/pi/sites/main;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html domain1_index.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
server {
root /home/pi/sites/main;
index index.html index.htm index.nginx-debian.html;
server_name internal.domain1.info; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/internal.domain1.info/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/internal.domain1.info/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
}
server {
if ($host = internal.domain1.info) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name internal.domain1.info;
return 404; # managed by Certbot
}
server {
server_name shiba.com www.shiba.com whispering.shiba.com;
location / {
proxy_pass http://<machine2'sIP>:8888;
}
}
server {
server_name yelling.shiba.com;
location / {
proxy_pass http://<machine2'sIP>:8555;
}
}
How can I get this to serve websites as specified in my picture?
Thanks.
Edit: My proposed new configuration
|sites-available | symlink --> | sites-enabled
conf1 | | conf1
#https website
server {
root /home/pi/sites/main;
index index.html index.htm index.nginx-debian.html;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/internal.domain1.info/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/internal.domain1.info/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
}
#http website redirect
server {
if ($host = internal.domain1.info) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name internal.domain1.info;
return 404; # managed by Certbot
}
|sites-available | symlink --> | sites-enabled
conf2 | | conf2
server {
listen 80 ;
listen [::]:80 ;
server_name whispering.shiba.info;
return 301 http://xxx.xxx.x.xx:8555;
}
|sites-available | symlink --> | sites-enabled
conf3 | | conf3
server {
listen 80 ;
listen [::]:80 ;
server_name yelling.shiba.info;
return 301 http://xxx.xxx.x.xx:8888;
}