skip to Main Content

After installing let’s encrypt via certbot my wordpress website has stopped loading css/js properly. It always returns Blocked loading mixed active content. If I change http://example.com to https://example.com in WP admin panel website server returns too many redirections error.

Here are some details.

My Nginx Config

server {
    server_name example.com www.example.com

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8000;
        include /etc/nginx/mime.types;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/vergisistemi.az/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/vergisistemi.az/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.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
    # return 404; # managed by Certbot

}

Here is what docker ps returns:

CONTAINER ID   IMAGE                PORTS                                   NAMES
571d2d2c7e12   wordpress:latest     0.0.0.0:8000->80/tcp, :::8000->80/tcp   wordpress
265b6e159bc2   mysql:5.7            3306/tcp, 33060/tcp                     mysql

2

Answers


  1. Chosen as BEST ANSWER

    After a half day in a searching for solution I figured out that some minor changes need to be made:

    1st - adding define('FORCE_SSL_ADMIN', true); to wp-config.php file;

    2nd - adding proxy_set_header X-Forwarded-Proto $scheme; to location in nginx config file:

    location / {
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8000;
            include /etc/nginx/mime.types;
        }
    

    And voilĂ ! Everything works smoothly!


  2. Adding this code to the top of wp-config.php did the trick for me:

    define('FORCE_SSL_ADMIN', true);
    
    if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS']='on';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search