Score:0

Nginx won't serve images with proper headers (example + conf provided)

ec flag

Here is an example of an image that is being served incorrectly :

https://www.questionhosting.com/product/temp.jpg

here is my config

server {
    listen   80;
    listen   443 ssl;
    listen   [::]:80 default ipv6only=on;
    listen   [::]:443 ssl ipv6only=on;

    server_name questionhosting.com;
    ssl_certificate     /etc/nginx/ssl/ssl.crt;
    ssl_certificate_key /etc/nginx/ssl/ssl.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    root /var/www/public;
    index index.php index.html index.htm;

    # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
    sendfile off;

    # Add stdout logging
#    error_log /dev/stdout info;
#    access_log /dev/stdout;
    error_log  /var/log/nginx/error.log warn;
    access_log  /var/log/nginx/access.log main;

    # Add option for x-forward-for (real ip when behind elb)
    #real_ip_header X-Forwarded-For;
    #set_real_ip_from 172.16.0.0/12;

    # Hide ALL kind of hidden stuff.
    location ~ /\. {
        return 403;
    }

    # Direct deliver certain files
    location ^~ ^\/(template|plugin|product|block|module).+\.(css|js|jpeg|gif|png|jpg){
        include /etc/nginx/mime.types;
        access_log      off;
        add_header      Cache-Control   "public";
        add_header      Pragma          "public";
        expires         30d;
        log_not_found   off;
        tcp_nodelay     off;
        try_files       $uri =404;
    }

    location / {
        include /etc/nginx/mime.types;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_read_timeout 1200;
        include fastcgi_params;
#        fastcgi_pass fpm;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
#        fastcgi_pass 127.0.0.1:9000;
#        fastcgi_pass cryptoweighter.questiondevelopment.com:9000;



        # First attempt to serve file, then as directory, then fall back to routing by the main index.php file
        try_files $uri $uri/ /index.php?$query_string;
    }
}

My goal was to directly load certain file extensions that resided in certain folders only. The rest of the requests I wanted to be sent to /var/www/public/index.php to be processed by that file. This config worked in another server of mine but when I moved it over here it stopped. Any help would be appreciated.

Richard Smith avatar
jp flag
You have a typo in your `location` expression. It should use `~` or `~*`, and **not** `^~` which means something totally different.
hendr1x avatar
ec flag
Thank you @RichardSmith . That was it. If you want credit please submit an answer and I will mark correct. Regardless, I appreciate your help
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.