Score:0

wordpress nginx in docker lost css styles, js because embed file hostname in html not updated

cn flag

We are trying to install wordpress on nginx on docker. The domain pointing to it is ssl enabled and when accessing the website, html is loading well but css, js, images are all lost.

The reason is html still using wordpress hostname(which i think only work locally on docker containers) to embed css, js, image files from docker container that running the wordpress image.

here where I inspect: https://i.stack.imgur.com/N5YO6.png

my nginx config:

server {
    listen 80;
    server_name my_domain.com www.my_domain.com;

    # Redirect http to https
    location / {
        return 301 https://my_domain.com$request_uri;
    }
}

server {
    listen 443 ssl http2;
    ...
    location / {
        proxy_pass http://wordpress_host:80;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            proxy_pass http://wordpress_host:80;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
            deny all;
    }

    location = /favicon.ico {
            log_not_found off; access_log off;
    }
    location = /robots.txt {
            log_not_found off; access_log off; allow all;
    }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;
    }
}

How can I config nginx, wordpress to resolve this?

Ivan Shatsky avatar
gr flag
What do you have in "WordPress Address (URL)" and "Site Address (URL)" (Settings -> General)?
Kim Mỹ avatar
cn flag
is that the wp dashboard that is visible only when finish setting up wordpress?
Ivan Shatsky avatar
gr flag
Yes, I mean WP dashboard (Settings -> General).
Kim Mỹ avatar
cn flag
I haven't got there only in the language choosing. Does changing the config.php file have the same effect?
Kim Mỹ avatar
cn flag
I set site address but only partial number of links gets https appended, the rest still is http appended. And I cannot go wp-admin anymore because http is loaded over https
Ivan Shatsky avatar
gr flag
Try adding `fastcgi_param HTTPS on;` and `fastcgi_param HTTP_SCHEME https;` to your PHP handler location.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.