0

I am having a Ubuntu 20.04.1 LTS and I am running nginx/1.18.0 (Ubuntu).

I am basically have three config files in my folder /etc/nginx/sites-available as I would like to route requests to:

  1. myserver.com
  2. immos.myserver.com
  3. items.myserver.com

My myserver.com config file looks like the following:

server { server_name myserver.com www.myserver.com; root /var/www/main-application/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/myserver.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/myserver.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 } server { if ($host = www.myserver.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = myserver.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name myserver.com www.myserver.com nlg.myserver.com; return 404; # managed by Certbot } 

The nginx-config of my immos.myserver.com looks like the following:

server { listen 80; server_name immos.myserver.com; root /var/www/immos-application/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } } 

My nginx config of items.myserver.com looks like the following:

server { listen 80; server_name items.myserver.com; root /var/www/items_application/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } } 

All the subdomains and the domain is routed on the DNS to my server's ip.

I can open myserver.com and get routed to the correct page.

BUT when opening immos.myserver.com, items.myserver.com I get routed to the application that is running on myserver.com.

All three applications are laravel applications.

Any suggestions what I am doing wrong?

2
  • 2
    Your subdomains are only configured for http. Are you trying to access them via https? Commented Sep 18, 2021 at 20:20
  • Are these files only in sites-available or did you also link them in sites-enabled and bounce nginx? If not, nginx isn't actually reading them. See serverfault.com/questions/424452/nginx-enable-site-command Commented Sep 19, 2021 at 13:13

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.