By ut4utc
Hi there,
I have a troble with nginx, when I want see this file - nginx show me 404 not found.
https://bytecode.com.ua/wp-content/uploads/Дибилы-завязывающие-с-выпивкой.mp4
My nginx config /etc/nginx/nginx.conf:
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
charset UTF-8;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 512;
types_hash_bucket_size 128;
client_max_body_size 160M;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
#gzip_vary on;
#gzip_proxied any;
#gzip_comp_level 6;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# add http2
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;
}
My website config /etc/nginx/sites-available/bytecode.com.ua
server {
root /var/www/bytecode.com.ua/public_html;
index index.html index.htm index.php;
server_name bytecode.com.ua www.bytecode.com.ua;
charset utf-8;
# HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# включаем сжатие gzip
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
# Static Content
location ~* ^.+\.(jpg|jpeg|gif|png|ico|tiff|css|js)$ {
expires 6M; # Кеширум на 6 месяцев
add_header Cache-Control public;
add_header Pragma public;
rewrite "^(.*);jsessionid=(.*)$" $1 permanent;
}
# ETAG
location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {
expires 2592000;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl http2; #ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/bytecode.com.ua/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/bytecode.com.ua/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 = www.bytecode.com.ua) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name bytecode.com.ua www.bytecode.com.ua;
return 404; # managed by Certbot
}
File really staying at this path and really located on hdd: https://bytecode.com.ua/wp-content/uploads/Дибилы-завязывающие-с-выпивкой.mp4
Pleace help me with configuration UTF8 nginx.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey,
The issue you’re experiencing with serving files containing Russian characters (or any non-ASCII characters) in their names comes down to how nginx and the filesystem handle these characters. When you access a URL with non-ASCII characters, your browser sends the request using percent-encoding (URL encoding). Nginx receives this encoded URL and tries to match it against files on the filesystem, which expects UTF-8 encoded filenames.
To resolve this issue, you need to ensure nginx decodes the percent-encoded URLs before trying to serve the files. Starting from nginx 1.11.0, the ngx_http_core_module has a directive called try_files, which you’re already using, but the problem likely lies in the encoding mismatch rather than the directive itself.
Here are a few steps to troubleshoot and potentially solve the problem:
Make sure your filesystem and nginx are using the same character encoding. Most modern Linux distributions use UTF-8 by default, but it’s good to confirm.
Nginx 1.11.0 introduced the escape=none parameter for the try_files directive, which stops nginx from percent-encoding URIs. However, this won’t help with decoding, but it’s useful to know for troubleshooting URI encoding issues.
Consider using the nginx map directive to decode the URL. This solution requires the HttpRewriteModule and may not directly apply to decoding percent-encoded UTF-8 characters but can be adapted for specific cases. A more straightforward approach involves ensuring that the client (browser) and server correctly handle URL encoding/decoding, which is usually automatic but can be influenced by server configuration and HTML page headers.
Your nginx configuration correctly specifies charset utf-8;, which should instruct nginx to use UTF-8 when serving files. However, this directive mainly affects the Content-Type header nginx sends back, not the interpretation of URIs.
Check your nginx access logs (/var/log/nginx/access.log) to see how the request URL for the file with Russian characters appears. It should give you insight into whether nginx is receiving the percent-encoded URL and whether it’s an encoding issue or a file path issue.
As a manual test, try accessing the file by using its percent-encoded URL directly in the browser. You can use online tools to convert “Дибилы-завязывающие-с-выпивкой.mp4” to its percent-encoded representation and then try accessing that URL. If this works, the issue is likely related to how browsers encode URLs before sending them to the server.
As a workaround, consider renaming files to use only ASCII characters in their names. This is not ideal for many reasons but can serve as a quick fix while you investigate the encoding issue.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.