• Resolved andrelauret23

    (@andrelauret23)


    Hello,
    It don’t work on my Yunohost Nginx server. At the browser side I got too many redirects.

    Here is wordpress.conf

    location / {
        # Path to source
        root /var/www/wordpress;
    
        index index.php;
        try_files $uri $uri/ /index.php?$args;
        client_max_body_size 30m;
    
        location ~ \.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_pass unix:/var/run/php/php8.0-fpm-wordpress.sock;
    
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    
    location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ogg|ogv|svgz|eot|otf|mp4|rss|atom|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        root /var/www/wordpress;
        expires max;
        add_header Cache-Control "public, no-transform";
        access_log off;
        log_not_found off;
    }
    
    location = /robots.txt {
        root /var/www/wordpress;
        access_log off;
        log_not_found off;
    }
    
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    Here is webpavif.conf

    location ~* wp\-content/(?!cache/fastware\-webpavif).+\.(jpe?g|png|gif|bmp|webp)$ {
        rewrite /wp\-content/(.+)$ /wp-content/cache/fastware-webpavif/$1;
    }
    
    location ~* cache/fastware\-webpavif.+\.(jpe?g|png|gif|bmp)$ {
        add_header Vary Accept;
        try_files $uri.pref$webp $uri.pref$avif $uri$webp $uri$avif $uri /?fw-webp-avif-ondemand=all;
    }
    
    location ~* cache/fastware\-webpavif.+\.webp$ {
        add_header Vary Accept;
        try_files $uri$png /?fw-webp-avif-ondemand=png;
    }
    2023/05/12 13:39:27 [error] 38559#38559: *1164 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 79.93.117.35, server: *****, request: "GET /wp-content/uploads/2022/11/rhum-apprecie-compress.jpg HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.0-fpm-wordpress.sock:", host: "*****", referrer: "*****"
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author richarddegoffau

    (@richarddegoffau)

    Hi @andrelauret23,

    Did you also add the lines in the http section?

    map $http_accept $webp {
        default ".nonexisting";
        "~*image/webp" ".webp";
    }
    
    map $http_accept $png {
        default ".png";
        "~*image/webp" "";
    }
    
    map $http_accept $avif {
        default ".nonexisting";
        "~*image/avif" ".avif";
    }
    Thread Starter andrelauret23

    (@andrelauret23)

    Yes I also added missing avif mimetype , here is main conf

    mmap $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    
    map $http_accept $webp {
        default ".nonexisting";
        "~*image/webp" ".webp";
    }
    
    map $http_accept $png {
        default ".png";
        "~*image/webp" "";
    }
    
    map $http_accept $avif {
        default ".nonexisting";
        "~*image/avif" ".avif";
    }
    
    server {
        listen 80;
        listen [::]:80;
        server_name www.rhum-www.com;
    
        access_by_lua_file /usr/share/ssowat/access.lua;
    
        include /etc/nginx/conf.d/acme-challenge.conf.inc;
    
        location ^~ '/.well-known/ynh-diagnosis/' {
            alias /tmp/.well-known/ynh-diagnosis/;
        }
    
    
        location ^~ '/.well-known/autoconfig/mail/' {
            alias /var/www/.well-known/www.rhum-www.com/autoconfig/mail/;
        }
    
    
    
    
        location / {
            return 301 https://$http_host$request_uri;
        }
    
    
    
        include /etc/nginx/conf.d/yunohost_http_errors.conf.inc;
    
        access_log /var/log/nginx/www.rhum-www.com-access.log;
        error_log /var/log/nginx/www.rhum-www.com-error.log;
    }
    
    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.rhum-www.com;
    
        include /etc/nginx/conf.d/security.conf.inc;
    
        ssl_certificate /etc/yunohost/certs/www.rhum-metiss.com/crt.pem;
        ssl_certificate_key /etc/yunohost/certs/www.rhum-metiss.com/key.pem;
    
    
        more_set_headers "Strict-Transport-Security : max-age=63072000; includeSubDomains; preload";
    
    
        # OCSP settings
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_trusted_certificate /etc/yunohost/certs/www.rhum-www.com/crt.pem;
        resolver 127.0.0.1 127.0.1.1 valid=300s;
        resolver_timeout 5s;
    
    
    
        location ^~ '/.well-known/autoconfig/mail/' {
            alias /var/www/.well-known/www.rhum-www.com/autoconfig/mail/;
        }
    
    
        access_by_lua_file /usr/share/ssowat/access.lua;
    
        include /etc/nginx/conf.d/www.rhum-www.com.d/*.conf;
    
        include /etc/nginx/conf.d/yunohost_sso.conf.inc;
        include /etc/nginx/conf.d/yunohost_admin.conf.inc;
        include /etc/nginx/conf.d/yunohost_api.conf.inc;
        include /etc/nginx/conf.d/yunohost_http_errors.conf.inc;
    
        access_log /var/log/nginx/www.rhum-www.com-access.log;
        error_log /var/log/nginx/www.rhum-www.com-error.log;
    }ain conf file
    

    NB: domain name has been modified for privacy

    Thread Starter andrelauret23

    (@andrelauret23)

    The issue seams to be caused by wordpress, he is doing the redirection:

    root@*******:/etc/nginx/conf.d/www.*****.com.d# curl -I https://www.*******.com/wp-content/uploads/2022/11/metiss-logo-compress.webp
    HTTP/2 302
    server: nginx
    date: Sat, 13 May 2023 06:31:13 GMT
    content-type: text/html; charset=UTF-8
    x-sso-wat: You've just been SSOed
    x-redirect-by: WordPress
    location: /wp-content/uploads/2022/11/metiss-logo-compress.webp
    content-security-policy: upgrade-insecure-requests
    x-content-type-options: nosniff
    x-xss-protection: 1; mode=block
    x-download-options: noopen
    x-permitted-cross-domain-policies: none
    x-frame-options: SAMEORIGIN
    permissions-policy: interest-cohort=()
    strict-transport-security: max-age=63072000; includeSubDomains; preload
    Plugin Author richarddegoffau

    (@richarddegoffau)

    Hi @andrelauret23,

    What do you see on the plugin settings page? Any messages?
    It seems the nginx rewrite rules are not working properly, but I don’t see why yet.
    Does the directory “/wp-content/cache/fastware-webpavif” exist?

    Thread Starter andrelauret23

    (@andrelauret23)

    Hello
    I see that on plugin page

    root@host:/var/www/wordpress# ls wp-content/cache/fastware-webpavif
    plugins  uploads

    Directory exists

    What is your nginx -t command shows? I got a similar error the first time I try it, but I had an error into the nginx.conf. After correct it, it works fine for me. The server changes must be just before “location /” line, and in my case, I have to remove the jpg, webp, gif… from original location…. something like from this:

    location ~* .(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ogg|ogv|svgz|eot|otf|mp4|rss|atom|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ to

    location ~* .(svg|woff|woff2|ttf|css|js|ogg|ogv|svgz|eot|otf|mp4|rss|atom|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ You can try this.

    Thread Starter andrelauret23

    (@andrelauret23)

    Thank you for the reply ! Here is wordpress.conf, I have deleted webpavif.conf and moved changes before location /

    root@******:/etc/nginx/conf.d/********# cat wordpress.conf
    location ~* wp\-content/(?!cache/fastware\-webpavif).+\.(jpe?g|png|gif|bmp|webp)$ {
        rewrite ^/wp-content/(.+)$ /wp-content/cache/fastware-webpavif/$1 last;
    }
    
    location ~* cache/fastware\-webpavif.+\.(jpe?g|png|gif|bmp)$ {
        add_header Vary Accept;
        try_files $uri.pref$webp $uri.pref$avif $uri$webp $uri$avif $uri /?fw-webp-avif-ondemand=all;
    }
    
    location ~* cache/fastware\-webpavif.+\.webp$ {
        add_header Vary Accept;
        try_files $uri$png /?fw-webp-avif-ondemand=png;
    }
    
    location / {
        root /var/www/wordpress;
    
        index index.php;
        try_files $uri $uri/ /index.php?$args;
        client_max_body_size 30m;
    
        location ~ \.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_pass unix:/var/run/php/php8.0-fpm-wordpress.sock;
    
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    
    location ~* .(svg|woff|woff2|ttf|css|js|ogg|ogv|svgz|eot|otf|mp4|rss|atom|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        root /var/www/wordpress;
        expires max;
        add_header Cache-Control "public, no-transform";
        access_log off;
        log_not_found off;
    }
    
    location = /robots.txt {
        root /var/www/wordpress;
        access_log off;
        log_not_found off;
    }
    
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    root@******:/etc/nginx/conf.d/********# nginx -t
    nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    But I continue to get Failed to load resource, ERR_TOO_MANY_REDIRECTS

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Too Many Redirect’ is closed to new replies.