Tuning sites for wordpress - php and nginx modules, settings, directives

Discussion in 'Installation/Configuration' started by chrisale, Feb 26, 2024.

  1. chrisale

    chrisale Member

    Hi all,
    I've been playing around with various php settings, php modules, and ngnix directives trying to get it right for my busy wordpress blogs. I have a few questions:
    1) Are the modules installed for the various php versions on the system supposed to be consistent? For example, wordpress depends heavily on imagick rather than gd, yet if I specify php8.2 ISPConfig delivers GD, whereas php8.3 delivers imagick. Why are they different?

    2) the php settings in each site's Options tab: can I assume any php setting in there will be applied or is it potentially being over-ruled somewhere else?

    3) I have had trouble getting nginx directives to apply. I have "header too big" messages appearing regardless what I put in the site nginx directive box. What is the best way to use the nginx directive box? What context (server? http? location?) are directives being injected into the nginx conf file when they are in the nginx directives box?

    This is what I have in the php and nginx boxes currently:

    PHP:
    Code:
    memory_limit = 512M
    post_max_size = 100M
    upload_max_filesize = 100M
    max_execution_time = 1200
    max_input_time = 1200
    magic_quotes_gpc = Off
    file_uploads = Yes
    max_file_uploads = 20
    open_basedir = none
    
    And this is in nginx:
    Code:
    if (!-e $request_filename) { rewrite ^.* /index.php break; }
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    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;
    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 64k;
    fastcgi_busy_buffers_size 64k;
    client_max_body_size 50M;
    proxy_busy_buffers_size 512k;
    proxy_buffers 4 512k;
    proxy_buffer_size 256k;
            }
    
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
    
    
    
     
  2. chrisale

    chrisale Member

    I've fixed some of this.
    From what I can gather, it appears there was some sort of conflict with some of the nginx directives, though no indication of this in the ISPConfig interface. Only going to the website's vhost log showed nginx complaining that the configuration was invalid and the previous working vhost file would be used.

    (It would be great if this was reported in the ISPConfig interface... since all it does is bring us back to the same directive)

    I have landed on this Nginx configuration after some trial and error to see when it would reject it or not based on the logs.
    From what I understand, there is no "location /" or "location ~* directive, so adding those doesn't have any impact.

    The location @php is more of a challenge but it seems if I replace it in full then it works. I was able to get the fastcgi buffers directives in there. It needed to come after the param according to my research.

    Code:
    location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
    location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php8.2-fpm/web21.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                fastcgi_buffers 16 32k;
                fastcgi_buffer_size 64k;
                fastcgi_busy_buffers_size 64k;
            }
    
    I'm still a little confused why PHP8.2 has different modules loaded from PHP8.3 but this is working for my wordpress install for now in PHP8.3. If I tweak it some more I'll update this thread.
     
    Last edited: Feb 27, 2024
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    If you are familiar with Nginx, then you probably know that Nginx does not allow it to override locations by placing a new location in a config file. But ISPConfig has a built-in system that allows it to modify and merge Nginx config locations, so you can do what Nginx does not support by itself in ISPConfig. You should read the ISPConfig manual; it is explained there how to do that. You can also find examples of this here in the forum when you e.g. search for nginx in conjunction with ##merge##

    The PHP configuration part of your above configuration is quite bad as it uses a hardcoded PHP-FPM socket, so you can't fully manage that site in ISPConfig. Use the placeholder variable for the socket instead.

    It is reported as a warning in ISPConfig GUI in the ispconfig system log unless you disabled warnings.
     
  4. chrisale

    chrisale Member

    I took that @php directive directly from the vhost file created by ISPConfig at /etc/nginx/sites-available so that I could build it with the buffers. What would be the best value there then?
     
  5. chrisale

    chrisale Member

    Yes, in the log. But you have to go looking for that, which you have no way of knowing if you're not already aware there is a problem. It would be better if when the change is requested and the file is not updated, the interface itself notifies us that the change wasn't successful. Perhaps in the red circle that appears showing a change is pending, instead of simply disappearing, it could indicate a problem.
     
  6. chrisale

    chrisale Member

    I've made some good progress here. Thank Til for the pointer to the "merge" I had not seen that in the manual.

    This is my directive currently. It seems to be working well. I needed to add the client_max_body_size to eliminate JSON errors from Wordpress.
    For others to find who might not be familiar with Nginx, I also included at the bottom a location directive to give multiple directories a file listing using a regular expression.
    The paths are:
    /NOAA/
    /ECCC/
    and /fire/

    Thanks for your help again.
    It's getting very close to being where I need it to be.

    Code:
    client_max_body_size 100M;
    location / {
                    try_files $uri $uri/ /index.php?$args;
            }
    
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                    expires max;
                    log_not_found off;
            }
    location @php { ##merge## 
                fastcgi_buffers 256 16k;
                fastcgi_buffer_size 128k;
                fastcgi_busy_buffers_size 256k;
            }
    
    location ~ ^/(NOAA|ECCC|fire)/ {
        autoindex on;
        autoindex_exact_size off;
        autoindex_format html;
        autoindex_localtime on;
    }
    
     

Share This Page