Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHARE-343 Serve .webp images #829

Merged
merged 1 commit into from Sep 15, 2020
Merged

SHARE-343 Serve .webp images #829

merged 1 commit into from Sep 15, 2020

Conversation

dmetzner
Copy link
Collaborator

@dmetzner dmetzner commented Aug 13, 2020

  • automatically serving webp images if supported by the client. Fallback remains jpeg/png

  • new local Nginx config (must be adapted manually):

# First, make sure that NGINX' `mime.types` file includes 'image/webp webp'
include /etc/nginx/mime.types;

# Checking if HTTP's `ACCEPT` header contains 'webp'
# if not supported - just download uri
# if supported - define path that cant be found .. fallback will be webp converter
map $http_accept $handle_webp {
  default $uri;
  "~*webp" "use_webp_fallback";
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    client_max_body_size 768M;

    ssl_certificate     /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
    ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM;
    fastcgi_param HTTPS on;

    root /var/www/catroweb/pr829/public/;

    server_name pr829-web.catrobat.ist.tugraz.at;

    location ~* ^.+\.(jpe?g|png) {
        # images should be served in webp format if supported by client
        set $args $args&source=$document_root$fastcgi_script_name;
        try_files $handle_webp /webp-on-demand.php$is_args$args;                                                                                                                                                                                                    
    }

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS on;
        fastcgi_param HTTP_SCHEME https;
        keepalive_timeout 90;

        fastcgi_buffers 32 4k;                                                                                                                                                                                                                                                                                                                                       
        fastcgi_buffer_size 32k;

        send_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;

        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    access_log /var/log/nginx/access.log combined;
    error_log /var/log/nginx/error.log warn;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
}
  • Docker config fixed

  • new local VirtualHost Apache settings (must be adapted manually):

<VirtualHost *:80>
        ServerName share
        ServerAlias share.catrob.at
        DocumentRoot /var/www/catroweb

        <Directory /var/www/catroweb>

             RewriteEngine On

             # Redirect images to webp-on-demand.php (if browser supports webp)
             RewriteCond %{HTTP_ACCEPT} image/webp
             RewriteCond %{REQUEST_FILENAME} -f
             RewriteRule ^(.*)\.(jpe?g|png)$ /webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]
             AddType image/webp .webp

             # Default Symfony routing
             DirectoryIndex /index.php
             FallbackResource /index.php

        </Directory>

        SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

May have to run:

a2enmod rewrite
systemctl restart apache2

@dmetzner dmetzner added the WIP label Aug 13, 2020
@dmetzner dmetzner changed the title webP images SHARE-343 webP images Aug 13, 2020
@dmetzner dmetzner changed the title SHARE-343 webP images SHARE-343 serve webP images Aug 13, 2020
@dmetzner dmetzner added no auto-deploy Disable auto-deploy and removed no auto-deploy Disable auto-deploy labels Aug 14, 2020
@codecov
Copy link

codecov bot commented Aug 14, 2020

Codecov Report

Merging #829 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop     #829   +/-   ##
==========================================
  Coverage      43.43%   43.43%           
  Complexity      4308     4308           
==========================================
  Files            569      569           
  Lines          15116    15116           
==========================================
  Hits            6565     6565           
  Misses          8551     8551           
Flag Coverage Δ Complexity Δ
#behat 41.79% <ø> (ø) 4308.00 <ø> (ø)
#phpunit 7.71% <ø> (ø) 4308.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef6d751...c5ac0b3. Read the comment docs.

@dmetzner dmetzner changed the title SHARE-343 serve webP images SHARE-343 Serve .webp images Aug 15, 2020
@dmetzner dmetzner marked this pull request as ready for review August 15, 2020 08:51
@dmetzner dmetzner added enhancement gsoc Ths pull request is from a "Google Summer of Code" Contributor and removed WIP labels Aug 17, 2020
Copy link
Contributor

@HCrane HCrane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works accordingly -- native IOS tests pending!

- additional server configs are added to the Pull request #829
@dmetzner dmetzner merged commit 099cdf3 into Catrobat:develop Sep 15, 2020
@dmetzner dmetzner deleted the SHARE-343 branch September 21, 2020 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement gsoc Ths pull request is from a "Google Summer of Code" Contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants