Enabled HTTPS and trying to redirect but getting 502 Bad Gateway

January 23, 2018 781 views
Nginx WordPress Ubuntu
grrrero
By:
grrrero

I've been trying to get my domain to redirect to HTTPS but I keep getting a 502 Bad Gateway error… Here’s my config:

server {
        listen 85 default_server;
        listen [::]:85 default_server;
        server_name domain.com www.domain.com;
        return 301 https://$server_name$request_uri;
}
server {

        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/domain.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_name domain.com www.domain.com;
        root /var/www/html;
        index index.php;

        client_max_body_size 100M;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index index.php;
                include fastcgi_params;
        }
        location ~ /\.ht {
                deny all;
        }
}
1 comment
  • I closed my session and reopened and now whenever I try to access the https version it does not open at all and just downloads the "index.php" file from Wordpress:

    <?php
    /**
     * Front to the WordPress application. This file doesn't do anything, but loads
     * wp-blog-header.php which does and tells WordPress to load the theme.
     *
     * @package WordPress
     */
    
    /**
     * Tells WordPress to load the WordPress theme and output it.
     *
     * @var bool
     */
    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    
Be the first one to answer this question.