Contao-Camp 2024
Ergebnis 1 bis 5 von 5

Thema: nginx.conf caching / expires headers funktioniert noch nicht richtig

  1. #1
    Contao-Fan
    Registriert seit
    28.02.2011.
    Beiträge
    675

    Standard nginx.conf caching / expires headers funktioniert noch nicht richtig

    Hallo zusammen,

    ich bin gerade am experimentieren mit einer nginx-conf für ein contao.
    Caching in contao ist aktiviert.

    Ich kriege aber immer noch ein Contao-Cache: miss

    Code:
    ?  ~ curl -sS -D - http:/test.test.de/ -o /dev/null
    HTTP/1.1 200 OK
    Server: nginx/1.17.6
    Content-Type: text/html; charset=utf-8
    Content-Length: 30421
    Connection: keep-alive
    Vary: Accept-Encoding
    Date: Mon, 18 Jan 2021 13:51:47 GMT
    Cache-Control: max-age=900, private
    Vary: Origin
    Vary: Cookie
    x-powered-by: PHP/7.3.19
    X-Content-Type-Options: nosniff
    Referrer-Policy: no-referrer-when-downgrade, strict-origin-when-cross-origin
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    Contao-Private-Response-Reason: authorization
    Contao-Cache: miss
    Age: 0
    und pingdom sagt mir, ich solle "Add Expires headers", wobei ich dachte ich hätte das getan.

    die nginx.conf sieht mittlerweile so aus:

    Code:
    pagespeed off;
    }
    location /system/modules/catalog-manager/assets/awesomplete {
        alias  /var/www/clients/client3/web285/web/v1/system/modules/catalog-manager/assets/awesomplete/;
    }
    
    location /system/modules/catalog-manager/assets {
        alias  /var/www/clients/client3/web285/web/v1/system/modules/catalog-manager/assets/; 
    }
    
    # - Web-Path zusätzlich anpassen/uebergeordnetes Verzeichnis hinzufuegen (PHP open_basedir:)
    # - Rechte fuer uebergeordnetes Verzeichnis anpassen
    # - PHP Optionen fuer Phar setzen 
    location / {
    	client_max_body_size 100M;
    
    	index app.php;
    	try_files $uri $uri/ /app.php$is_args$args;
    	
    	location ~ ^/(app|app_dev|config|install|preview|contao-manager\.phar)\.php(/|$) {
    		include /etc/nginx/fastcgi_params;
                    {FASTCGIPASS}
    		#fastcgi_pass unix:/var/lib/php7.2-fpm/web41.sock;
    		fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    		fastcgi_intercept_errors on;
    		
    		fastcgi_temp_file_write_size 10m;
    		fastcgi_busy_buffers_size    512k;
    		fastcgi_buffer_size          512k;
    		fastcgi_buffers           16 512k;
    		fastcgi_read_timeout 1200;
    		fastcgi_param HTTP_AUTHORIZATION $http_authorization;
    		
    	}
    }
    
    ## Directives to send expires headers and turn off 404 error logging.
    #location ~* #^.+\.(eot|otf|woff|woff2|ttf|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|webp|png)$ {
    #   expires max;
    #}
    ## CSS and Javascript send expires headers.
    #location ~* \.(?:css|js)$ {
    #  expires 1y;
    #}
    }
    
    ###added Jan 2021
    location ~* \.(?:eot|woff|woff2|ttf|svg|otf) {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
    
            # allow CORS requests
        add_header        Access-Control-Allow-Origin *;
    
        types     {font/opentype otf;}
        types     {application/vnd.ms-fontobject eot;}
        types     {font/truetype ttf;}
        types     {application/font-woff woff;}
        types     {font/x-woff woff2;}
    }
    
    location ~* \.(?:jwebp|pg|jpeg|gif|png|ico|xml)$ {
        expires 365d
        etag on;
        if_modified_since exact;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public";
    }
    
    location ~* \.(?:css|js)$ {
      access_log        off;
      log_not_found     off;
      add_header        Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
    }
    
    location ~ /\. { 
      access_log        off; 
      log_not_found     off; 
      deny              all; 
    }
    
    gzip on;
    gzip_disable "msie6";
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js image/svg+xml;
    gzip_buffers 16 8k;
    Viele Grüße,
    conter

  2. #2
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    33.898
    Partner-ID
    10107

    Standard

    Für die von Contao erzeugten Responses solltest du keinen Expires Header setzen. Contao liefert ja die korrekten Response Header selbst. Im Webserver selbst solltest du Caching Header nur für statische Ressourcen setzen.

    Zum Problem mit dem HTTP Cache von Contao selbst: Contao liefert auch einen zusätzlichen Response Header, der beschreibt warum dieser Response nicht aus dem HTTP Cache kommt. In deinem Fall ist der Grund, dass du in irgendeiner Form eingeloggt warst.

  3. #3
    Contao-Fan
    Registriert seit
    28.02.2011.
    Beiträge
    675

    Standard

    Hi Spooky,

    danke schon mal für die Antwort.

    Heißt das konkret, das gar keine caching-Sachen in die nginx-conf gehören? Oder nur die add_header Zeilen nicht?
    Wäre es so okay?

    Code:
    ###added Jan 2021
    location ~* \.(?:eot|woff|woff2|ttf|svg|otf) {
        expires 31536000s;
        etag on;
    
        types     {font/opentype otf;}
        types     {application/vnd.ms-fontobject eot;}
        types     {font/truetype ttf;}
        types     {application/font-woff woff;}
        types     {font/x-woff woff2;}
        types     {image/svg+xml}
    }
    
    location ~* \.(?:webp|jpg|jpeg|gif|png|ico|xml|css|js) {
        expires 31536000s;
        etag on;
    }
    Noch eine Frage: bei Chrome devtools Network: was ist Status 304 (network-cache.png), bzw. wie kriege ich das zu 200 bei js und css ?

    Außerdem sind meine Backend-svg-Icons verschwunden .... hat wahscheinlich auch mit meiner conf zu tun
    [ATTACH=CONFIG]Screenshot Dateiverwaltung[/ATTACH]


    Viele Grüße,
    conter
    Angehängte Grafiken Angehängte Grafiken
    Geändert von conter (19.01.2021 um 12:56 Uhr)

  4. #4
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    33.898
    Partner-ID
    10107

    Standard

    Zitat Zitat von conter Beitrag anzeigen
    Heißt das konkret, das gar keine caching-Sachen in die nginx-conf gehören?
    Doch, für statische Ressourcen, wie bspw. Bilder etc. natürlich schon.



    Zitat Zitat von conter Beitrag anzeigen
    Wäre es so okay?
    Das kann ich dir nicht sagen, ich bin kein nginx Experte.



    Zitat Zitat von conter Beitrag anzeigen
    was ist Status 304
    https://www.google.com/search?q=http+status+304

  5. #5
    Contao-Fan
    Registriert seit
    28.02.2011.
    Beiträge
    675

    Standard

    Danke, mit "if_modified_since exact;" ist der 304er ist jetzt weg

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •