• Hello I have tried method 1 and 2 from the FAQ about Nginx server but can’t get webp express to work, when I convert test image after configuration, I got a 404 not found.
    It’s a classic wp installation on ubuntu 18.04 nginx server on digitalocean.
    My file /etc/nginx/sites-available looks like:

    `server {
    root /var/www/mysite.be;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name mysite.be https://www.mysite.be;

    location / {
    # try_files $uri $uri/ =404;
    try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
    deny all;
    }

    location = /favicon.ico { log_not_found off; access_log off;
    }

    location ~* ^/wp-content/.*\.(png|jpe?g)$ {
    add_header Vary Accept;
    expires 365d;
    }
    location ~* ^/wp-content/.*\.webp$ {
    expires 365d;
    if ($whattodo = AB) {
    expires 365d;
    if ($whattodo = AB) {
    add_header Vary Accept;
    }
    }
    if ($http_accept ~* “webp”){
    set $whattodo A;
    }
    if (-f $request_filename.webp) {
    set $whattodo “${whattodo}B”;
    }
    if ($whattodo = AB) {
    rewrite ^(.*) $1.webp last;
    }
    if ($whattodo = A) {
    rewrite ^/wp-content/.*\.(jpe?g|png)$ /wp-content/plugins/webp-express/w$
    }
    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;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.be/fullchain.pem; # managed$
    ssl_certificate_key /etc/letsencrypt/live/mysite.be/privkey.pem; # manag$
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    }

    server {
    if ($host = https://www.mysite.be) {
    return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = mysite.be) {
    return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($http_accept ~* “webp”){
    rewrite ^/(.*).(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-de$
    }

    listen 80;
    server_name mysite.be https://www.mysite.be;
    return 404; # managed by Certbot

    } `

    What to do to get it to work ?

Viewing 15 replies - 1 through 15 (of 25 total)
  • Please try these configuration on your domain conf after server {

    location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
    add_header Vary Accept;
    expires max;
    if ($http_accept !~* “webp”){
    break;
    }
    try_files $uri.webp /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x$request_filename&wp-content=wp-content&$args;
    }

    location ~* ^/?wp-content/.*\.(png|jpe?g)\.webp$ {
    expires max;
    try_files $uri /wp-content/plugins/webp-express/wod/webp-realizer.php?wp-content=wp-content&$args;
    }

    Thread Starter tanuki1986

    (@tanuki1986)

    Thank you @nuevaya for your reply, I’m not sure I’ve done it correctly as there is two

    server{ in my file so here’s how look my file after adding your code

    `server {
    root /var/www/mysite.be;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name mysite.be https://www.mysite.be;

    location / {
    # try_files $uri $uri/ =404;
    try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    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;
    }

    location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
    add_header Vary Accept;
    expires max;
    if ($http_accept !~* “webp”){
    break;
    }
    try_files $uri.webp /wp-content/plugins/webp-express/wod/webp-on-demand$
    }

    location ~* ^/?wp-content/.*\.(png|jpe?g)\.webp$ {
    expires max;
    try_files $uri /wp-content/plugins/webp-express/wod/webp-realizer.php?w$
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.be/fullchain.pem; # managed$
    ssl_certificate_key /etc/letsencrypt/live/mysite.be/privkey.pem; # manag$
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    }

    server {
    if ($host = https://www.mysite.be) {
    return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = mysite.be) {
    return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name bobeauspa.be https://www.mysite.be;
    return 404; # managed by Certbot

    }

    I then did

    sudo systemctl restart nginx

    in wp dashboard settings>webp express> save settings > convert test image (show debug) and unfortunately got 404 not found again

    show me the log plz

    Thread Starter tanuki1986

    (@tanuki1986)

    @nuevaya If what you are asking is cat /var/log/nginx/error.log

    2019/07/11 10:50:11 [emerg] 31497#31497: “listen” directive is not allowed here in /etc/nginx/sites-enabled/mysite.be:77

    Thread Starter tanuki1986

    (@tanuki1986)

    @nuevaya was it what you asked when you asked to show the log?
    Any other ideas on how to get this to work, please?

    Show me the log on the convertion

    Thread Starter tanuki1986

    (@tanuki1986)

    Thank you @nuevaya for trying to help me.
    sorry, I don’t understand what I should show you.
    When I click the convert test image (show debug)
    I just get a 404 not found nothing else.

    Try to comment these lines

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

    Thread Starter tanuki1986

    (@tanuki1986)

    I commented out those lines and sudo systemctl restart nginx.
    Then Convert test image (show debug)
    again 404 not found ??

    Check what library is installed on your os GD or Imagemagick maybe that is missing

    Thread Starter tanuki1986

    (@tanuki1986)

    There is 2 conversion methods that are operational if I understood your question correctly.
    Those are cwebp and Gd extension.

    I believe the problem is within

    
    location / {
    # try_files $uri $uri/ =404;
    try_files $uri $uri/ /index.php$is_args$args;
    }
    

    If I’m correct, this redirects any request to the index.php.
    This also includes non-existing webp-files which therefore will not be sent to the converter.

    I’m encountering the same problem using the directive below and am still searching for a solution.

    
    # WORDPRESS PERMALINKS
    if (!-e $request_filename) {
    	rewrite ^(.+)$ /index.php?q=$1 last;
    }
    
    Plugin Author rosell.dk

    (@roselldk)

    “location / {” is a “prefix match”
    “location ~* ^/?wp-content/.*\.(png|jpe?g)$ {” is a “regex match”

    regex matches takes precedence over prefix matches meaning that if there is a location block with a regex match, the location block with the prefix match will not be used.

    If there are multiple location blocks that has a regex match, the first will be selected.

    I got this information from this article

    • This reply was modified 5 years, 2 months ago by rosell.dk.
    • This reply was modified 5 years, 2 months ago by rosell.dk.
    • This reply was modified 5 years, 2 months ago by rosell.dk.
    Plugin Author rosell.dk

    (@roselldk)

    I have updated the Nginx FAQ section – and the rules – since the first posts in this thread.
    Perhaps the changed rules works for you?

    I’ve tried both, but they don’t go together with the rewrite directive. Any attempt at creating an unexisting image on the fly fails because of the rewrite.

    I’ve tried to replace the rewrite lines with a Location block, but somehow I keep getting 404 not found errors using custom permalinks. The live webp generation works in this situation.

    I’ve also tried a combination of the above using the evil if statements. But the rewrite also messes things up there.

    I will try some more things when I’m at work.

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘nginx server 404 not found when convert test images’ is closed to new replies.