2

recently i configured wordpress site with docker and it runs on port 8080 and then i configured nginx reverse proxy on host and it was totally fine.. but sooner after i added ssl site wont load itz css and i can not find the error

    server {
  server_name mysite.com; # change this

  # global gzip on
#  gzip on;
#  gzip_min_length 10240;
#  gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
#  gzip_disable "MSIE [1-6]\.";

 # add_header Cache-Control public;

  location / {
    proxy_pass http://127.0.0.1:8080; # change this
    proxy_buffering on;
    proxy_buffers 12 12k;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
  }



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


  listen 80;
  server_name mysite.com;
    return 404; # managed by Certbot
}

3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jan 27, 2022 at 3:39
  • Got same error here. Any fix? Commented Feb 13, 2022 at 23:13
  • 1
    Got aiprose.com/blog/148 might help Commented Feb 13, 2022 at 23:24

1 Answer 1

4

List your docker containers to get your instance name

sudo docker ps -a

Access the wp-config.php on docker instance.

# Access your instance files 
sudo docker exec -i -t instance_name bash

# Install nano to edit files
apt install nano

nano wp-config.php

Add following at top of wp-config.php

define('FORCE_SSL_ADMIN', true);

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false){
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

Add following at end of wp-config.php. Repalce example.com with your domain name

define('WP_HOME','https://example.com/');
define('WP_SITEURL','https://exampe.com/');

In your nginx file ie /etc/nginx/sites-enabled/example.com, Ensure you have added proxy_set_header X-Forwarded-Proto https;

server {

    root /var/www/example.com;

    index index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

    location / {
            proxy_pass http://localhost:8000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Forwarded-Proto https;
    }



    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


}
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



    server_name example.com www.example.com;
    listen 80;
    return 404; # managed by Certbot




}

Now restart you docker instance

sudo docker restart instance_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.