Answer the question
In order to leave comments, you need to log in
Nginx Rewrite, how to solve the problem with images from a special folder?
Good day.
Before I installed NGINX on the server, I only had Apache on the server and, accordingly, the rules were written in htaccess
RewriteRule photos/(.+)$ modules/qplboard/image_db/$1
server {
access_log off;
error_log logs/vhost-error_log warn;
listen 80;
server_name mydomain.ru www.mydomain.ru;
location ~* \.(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid)$ {
root /home/username/public_html/mydomain.ru;
expires 14d;
}
location / {
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
# you can increase proxy_buffers here to suppress "an upstream response
# is buffered to a temporary file" warning
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_connect_timeout 30s;
proxy_redirect http://www.mydomain.ru:8080 http://www.mydomain.ru;
proxy_redirect http://mydomain.ru:8080 http://mydomain.ru;
proxy_pass http://192.168.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
location ~ ^/photos/(.*)$ {
rewrite ^/photos/(.+)$ /mydomain.ru/modules/qplboard/image_db/$1;
}
109.12.218.212 - - [15/Apr/2014:00:12:40 +0500] "GET /photos/8952_1_b.JPG HTTP/1.0" 304 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36"
location ~ ^/photos/(.*)$ {
root /mydomain.ru/modules/qplboard/image_db;
access_log off;
expires 14d;
}
Answer the question
In order to leave comments, you need to log in
Working code. Files from this folder are given by NGINX.
location ~ /photos/(.*)$ {
alias /home/username/public_html/mydomain.ru/modules/qplboard/image_db/$1;
expires 14d;
}
location ~^/photos/ {
alias /home/username/public_html/mydomain.ru/modules/qplboard/image_db;
}
~^/photos/.*\.(gif|jpg|jpeg|png|ico)$
, for example
@inkvizitor68sl tried in different ways, unfortunately nothing works.
Once it turned out "403 Forbidden", though I don't know why :-(
location ~^/photos/ {
alias /home/username/public_html/mydomain.ru/modules/qplboard/image_db;
}
location ~^/photos/(.*)$ {
alias /home/username/public_html/mydomain.ru/modules/qplboard/image_db/$1;
}
location ~ ^/photos/(.*)$ {
alias /home/username/public_html/mydomain.ru/modules/qplboard/image_db;
}
I continue experimenting with the NGINX config:
location ~ /photos/6426_1_b.JPG {
rewrite ^ /modules/qplboard/image_db/6426_1_b.JPG;
}
location ~ /photos/6426_1_b.JPG {
alias /modules/qplboard/image_db/6426_1_b.JPG;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question