You are not logged in.

#1 2022-02-23 20:18:18

Morta
Member
Registered: 2019-07-07
Posts: 660

WordPress not display correctly with nginx

Hi I have following problem

My site https://joelmueller.ch looks incomplete after immigration from Apache to nginx

My vhost looks like

upstream php {
       server unix:/run/php-fpm/php-fpm.sock;
}

server {
    listen 80 proxy_protocol;
    listen [::]:80 proxy_protocol;   
    server_name  joelmueller.ch www.joelmueller.ch;
    root /usr/share/webapps/blog;
    index index.php;
   
    location = /favicon.ico {
               log_not_found off;
               access_log off;
       }

       location = /robots.txt {
               allow all;
               log_not_found off;
               access_log off;
       }

       location / {
               # This is cool because no php is touched for static content.
               # include the "?$args" part so non-default permalinks doesn't break when using query string
               try_files $uri $uri/ /index.php?$args;
       }

       location ~ \.php$ {
               #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
               include fastcgi_params;
               fastcgi_intercept_errors on;
               fastcgi_pass php;
               #The following parameter can be also included in fastcgi_params file
               fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
       }

       location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
               expires max;
               log_not_found off;
       }
}

Also have the problem that want redirect https://joelmueller.ch/wp-admin

Offline

#2 2022-02-23 21:08:28

Bevan
Member
Registered: 2009-09-08
Posts: 102

Re: WordPress not display correctly with nginx

Hi,

I think the problem is that your site is accessed via https but it tries to load CSS and JavaScript files via http. Modern browsers block these "mixed" requests: https://imgur.com/a/YhJFbkm

Can you maybe update the URL of your blog in the wordpress settings or its config file to use https instead of http?

For https://joelmueller.ch/wp-admin/ the problem is that there is an infinite loop of redirects to the same URL. However, I cannot see a reason for that redirect in your nginx config.

Is there a forward proxy in front of your web server that handles HTTPS and maybe also redirects?

Offline

#3 2022-02-24 06:41:17

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: WordPress not display correctly with nginx

It‘s behind a Haproxy and is running on port 80 served by nginx.

How I change the whole WordPress from https to http?

I changed in the database siteurl and home to http://joelmueller.ch that fix the wp-admin issue but not the css and content problems

Offline

#4 2022-02-24 15:30:18

matse
Member
Registered: 2011-04-27
Posts: 299

Re: WordPress not display correctly with nginx

If you are behind a reverse proxy, make sure that you set the header "X-Forwarded-Proto".
In nginx (I don't know Haproxy) you would do it like:

RequestHeader set X-Forwarded-Proto "https"

Then wordpress should automatically detect, that you access it via https, normally your wp-config.php should (by default) have something like:

if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
	$_SERVER['HTTPS'] = 'on';
}

Greetings

matse

Offline

#5 2022-02-24 15:43:55

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: WordPress not display correctly with nginx

matse wrote:

If you are behind a reverse proxy, make sure that you set the header "X-Forwarded-Proto".
In nginx (I don't know Haproxy) you would do it like:

RequestHeader set X-Forwarded-Proto "https"

Then wordpress should automatically detect, that you access it via https, normally your wp-config.php should (by default) have something like:

if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
	$_SERVER['HTTPS'] = 'on';
}

Greetings

matse

When I put in location { the nginx -t fails. Where I have to put.

Very strange is on my laptop the site is working but on my iphone not.

I replace all url from https://joelmueller.ch to http://joelmueller.ch but on the iphone shows me a problem with the cert. On my laptop every thing is clean equal if the url is http or https in the config

Last edited by Morta (2022-02-24 15:50:54)

Offline

#6 2022-02-24 16:00:28

matse
Member
Registered: 2011-04-27
Posts: 299

Re: WordPress not display correctly with nginx

The code comes into the server block directly - and I forgot a ";" at the end of the line, the correct line is:

RequestHeader set X-Forwarded-Proto "https";

Also check, that the php code is in your wp-config.php.

Greetings

matse

Offline

#7 2022-02-24 16:30:54

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: WordPress not display correctly with nginx

matse wrote:

The code comes into the server block directly - and I forgot a ";" at the end of the line, the correct line is:

RequestHeader set X-Forwarded-Proto "https";

Also check, that the php code is in your wp-config.php.

Greetings

matse


2022/02/24 18:25:00 [emerg] 2128944#2128944: unknown directive "RequestHeader" in /etc/nginx/sites-enabled/blog.conf:11

Offline

#8 2022-02-24 16:42:22

matse
Member
Registered: 2011-04-27
Posts: 299

Re: WordPress not display correctly with nginx

Sorry, I was confused, the correct code is:

proxy_set_header    	X-Forwarded-Proto https;

//Edit:
But as I wrote, I don't know if this will work, if you use nginx as backend (not reverse proxy).
You can also set this header in haproxy, refer e.g. to this

Last edited by matse (2022-02-24 17:38:49)

Offline

Board footer

Powered by FluxBB