I currently have nginx setup for my server at my.server.com
. Using the current configuration I access different applications using http://my.server.com/app1
or http://my.server.com/app2
.
I have an apps.conf
placed in /etc/nginx/sites-enabled/
this is what it looks like:
upstream app1_servers {
server 172.12.11.10:8080;
}
upstream app2_servers{
server 172.12.11.10:9090;
}
server {
listen 80;
server_name my.server.com;
return 301 https://my.server.com/$request_uri; #force https
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/my.server.com/cert.pem;
ssl_certificate_key /etc/ssl/my.server.com/priv.pem;
server_name my.server.com;
location /app1 {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://app1_servers/app1;
proxy_redirect http://$host https://$host;
proxy_set_header Host $host;
}
location /app2 {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://app2_servers/app2;
proxy_redirect http://$host https://$host;
proxy_set_header Host $host;
}
}
Question
The above works fine. However, now I would like to change how I access app1
and app2
. I would like to access them by http://app1.my.server.com
and http://app2.my.server.com
while still maintaining force ssl and doing proxy_pass
What configuration changes do I need to make for this to take effect? Additionally, I would like to keep configuration settings for each application in its separate file.