skip to Main Content

I have a WordPress server inside a docker container. WordPress is running with a nginx server inside. When I go through the initial installation phase, css (and other files) worked perfectly. But the when I load the main site, those resources redirected to HTTP://example.com/blogs/… instead of HTTPS.

Here are the URLs from the inspect:

https://example.com/blogs/
http://example.com/blogs/wp-includes/js/wp-emoji-release.min.js?ver=5.1.1

Here are my Nginx configuration from example.com:

location /blogs/ {
                proxy_pass HTTP://localhost:8080/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 1800s;
        }

I have updated the wp-config.php file with the following information

define('WP_HOME','https://example.com/blogs/');
define('WP_SITEURL','https://example.com/blogs/');
$_SERVER['REQUEST_URI'] = '/blogs' . $_SERVER['REQUEST_URI'];

Please let me know if u need any more information.

— update #1 —

Nginx Server block

server {
        root /var/www/html;
        index index.php index.html index.htm;

        server_name example.com; # managed by Certbot
       
        location /blogs/ {
                proxy_pass HTTP://localhost:8080/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 1800s;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.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
    if ($scheme != https) {
          return 301 https://$host$request_uri;
    }
}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name example.com;
    return 404; # managed by Certbot
}

2

Answers


  1. Check in the wp_options table if siteurl and home are also set with https.

    Login or Signup to reply.
  2. assuming you have a server block for your domain, make sure you have these lines in your server block to redirect all non-https request to https:

        server {
            listen 80;
            listen 443 ssl http2;
            server_name example.com www.example.com;
    the rest of your code
            if ($scheme != https) {
                return 301 https://example.com$request_uri;
    the rest of your code
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search