Home Nginx HTTPS subdomain redirect
Reply: 0

Nginx HTTPS subdomain redirect

user2525 Published in May 23, 2018, 4:40 pm

I have a couple of websites configured with Nginx (nginx/1.10.3 (Ubuntu)) Server Blocks. Browsing to any of the configured domains listed below works as expected:

Those that are configured to use HTTPS get automatic HTTP -> HTTPS redirects (morgrowe.com for example). The issue is when I browse to a subdomain that doesn't exist (for example: doesnotexist.morgrowe.com). If I go to http://doesnotexist.morgrowe.com, I get redirected to the default Nginx page (which is what I want). However, if I go to https://doesnotexist.morgrowe.com, I get redirected to https://api.morgrowe.com.

This wouldn't be so bad, but if I go to https://doesnotexist.carpyslocksmiths.com, I also get redirected to https://api.morgrowe.com.

Where can I find the configuration that makes this happen? Ideally, I'd like the default nginx 404 page to appear like it does for http connections. I imagine I have to configure something in /etc/nginx/sites-available/default, but I don't know where to start. Here's my /etc/nginx/sites-available/default file contents:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.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;

    # pass the PHP scripts to FastCGI server listening on
    #location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #   # With php7.0-cgi alone:
    #   fastcgi_pass;
    #   # With php7.0-fpm:
    #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #   deny all;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.357936 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO