I can not remove the default page that NGINX has

September 19, 2017 259 views
Let's Encrypt Nginx WordPress PHP Security Ubuntu 16.04 Ubuntu

Hello, I have a problem that I can not solve well, the problem that I try to solve is that when installing a SSL certificate for free Let Encrypt always redirects me to the default page of NGINX telling me Welcome.

I have tried to look for that index, but I already have it removed and I do not know where it is taking, I really have a website already installed that should be displayed and not that default NGINX page when installing the SSL certificate, before installing SSL showed me my website without any problems, but now that I installed the free Let Encrypt SSL, it always shows me the default page containing NGINX.

this is my code server:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name zoneclass.com www.zoneclass.com;
    return 301 https://$server_name$request_uri;



    # 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/wordpress;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;



    location ~ /.well-known {
               allow all;
        }   

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }


    #Seguridad de acceso a PHPMyAdmin
    location /jsjf {
        auth_basic "Admin Login";
        auth_basic_user_file /etc/nginx/pma_pass;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #   # With php7.0-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # 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;
    #}

    #Especificar Cache en el navegador
    location ~* \.(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf|woff|ttf)$ {
        root /var/www/html/wordpress;
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
     }


}

#Configuracion SSL
server {

    # SSL configuration

    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-zoneclass.com.conf;
    include snippets/ssl-params.conf;
    }

What could I do to solve this problem and that my website can show up well with SSL?

2 Answers

@SmilJimenez

Try to move every thing after return 301 https://$server_name$request_uri; to the second server block.

Hope this helps.

  • I have moved everything to the second block with the following aspect of the code and now it shows the website, but SSL is not working and my website is not secure.

    this is my code now:

    server {
    
    
    
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name zoneclass.com www.zoneclass.com;
        return 301 https://$server_name$request_uri;    
    
    }
    
    
    
    #Configuracion SSL
    server {
    
        # SSL configuration
    
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;
        include snippets/ssl-zoneclass.com.conf;
        include snippets/ssl-params.conf;
    
    
         root /var/www/html/wordpress;
    
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm;
    
    
    
        location ~ /.well-known {
                   allow all;
            }   
    
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }
    
    
        #Seguridad de acceso a PHPMyAdmin
        location /jsjf {
            auth_basic "Admin Login";
            auth_basic_user_file /etc/nginx/pma_pass;
        }
    
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
        #
        #   # With php7.0-cgi alone:
        #   fastcgi_pass 127.0.0.1:9000;
        #   # 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;
        #}
    
        #Especificar Cache en el navegador
        location ~* \.(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf|woff|ttf)$ {
            root /var/www/html/wordpress;
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
         }
    
    
    
    
    
        }
    
    

I do not understand, where do you want me to try to put it? Excuse me and thank you for actually responding.

Have another answer? Share your knowledge.