Answer the question
In order to leave comments, you need to log in
Why are images in nginx passed as text/html?
Full stack application, everything worked fine on the local machine. After landing on nginx and getting ssl, everything works except for one thing, images from static are received in the wrong type, namely text/html:
Here are the configs:
/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
proxy_pass_header Content-Type;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
upstream client-upstream {
server 0.0.0.0:3000;
keepalive 15;
}
upstream back-upstream {
server 0.0.0.0:5000;
keepalive 15;
}
server {
server_name DOMAINNAME.ru www.DOMAINNAME.ru;
server_tokens off;
client_max_body_size 1000M;
root /var/www/prod/public;
index index.php index.html index.htm;
location / {
proxy_pass http://client-upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_upgrade;
proxy_set_header Host $host;
}
location /api {
proxy_pass http://back-upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/DOMAINNAME.ru/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/DOMAINNAME.ru/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = DOMAINNAME.ru) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name DOMAINNAME.ru www.DOMAINNAME.ru;
return 404; # managed by Certbot
}
client
src
components
some_component.js (достаются в виде https://DOMAIN.RU/file_name.jpg)
server
static (изображения хранятся здесь)
Answer the question
In order to leave comments, you need to log in
Two questions - who is in charge of specifying MIME and what types are specified in the configuration?
"In the forehead" solution - in the desired location specify add_header Content-Type image/jpg; But this is not very correct.
Here you will find the answer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question