Score:0

How do I setup nginx for multiple web app with multiple subdomains in GCE

th flag

I am using GCE with LEMP stack. I have multiple subdomains and each subdomain has different root folder.

My setup is as below:

Production app

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

    listen 443 ssl http2;
    listen [::]:443 ipv6only=on ssl http2;

    ssl_certificate /etc/nginx/ssl/*.example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/*.example.com.key;

    server_name prod.example.com;
    root /var/www/example/web;
    client_max_body_size 10M;
}

Staging app

server {
    listen [::]:80;
    listen [::]:443 ssl http2;
    
    ssl_certificate /etc/nginx/ssl/*.example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/*.example.com.key;

    server_name staging.example.com;
    root /var/www/example-staging/web;
    client_max_body_size 10M;
}

They have the same config except for the server_name part. But, it seems like nginx is not able to tell apart the 2 different configuration.

No matter if I were to use prod.example.com or staging.example.com, both will only route to the prod root folder.

Is there anything wrong with my configurations that is causing this issue?

jp flag
This question has no connection to Google Cloud Platform, it's all about NGINX configuration.
Score:1
cz flag

Your "staging" server block only listens on IPv6, but you are accessing your server via IPv4. You need to also add the IPv4 listen directives to that block.

David Yap avatar
th flag
can't believe that such a tiny mistake can cause such a big difference. Thank you!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.