Resizing Image Nginx on the Fly with Backend S3 - nginx

I've already installed nginx with module http image filter module and all dependencies. my nginx version 1.8.0.
here's my script :
server {
listen 80;
server_name my.domain.com;
location ~* / {
proxy_pass http://mydomain.s3-website-ap-southeast-1.amazonaws.com;
}
location ~* ^/resize/([\d\-]+)x([\d\-]+)/(.+)$ {
alias http://mydomain.s3-website-ap-southeast-1.amazonaws.com/$3;
image_filter resize $1 $2;
image_filter_buffer 2M;
error_page 415 = /empty;
}
location ~* ^/crop/([\d\-]+)x([\d\-]+)/(.+)$ {
alias http://mydomain.s3-website-ap-southeast-1.amazonaws.com/$3;
image_filter crop $1 $2;
image_filter_buffer 2M;
error_page 415 = /empty;
}
location = /empty {
empty_gif;
}
}
when i request http://my.domain.com/some_image.jpg, it's return no error
but when i try with http://my.domain.com/resize/300x300/some_image.jpg, it return 404 or not found
Update#1
I've change :
location ~* / {
to :
location / {
it's fix the error on my config.

Related

Nginx Rewrite Querystring to Path with file

I am creating a rule for S3, with Rewrite Querystring to Path with file
Requests from the browser to the server can be
http://localhost:8088/bucket-media/1111111_0.jpg?size=large
"size" is a directory in the s3 bucket, it needs to be proxied to S3
https://s3-storage/bucket-media/large/1111111_0.jpg
My config
set $bucket "s3-storage";
location /bucket-media/ {
#set $size $arg_size;
#rewrite ^ /$size$uri break;
if ($args ~* "size=(.*)") {
set $w1 $1;
rewrite .* /bucket-media/$w1/$uri break;
}
proxy_intercept_errors on;
resolver 8.8.8.8;
proxy_pass https://$bucket$uri;
error_page 404 = #fallback;
}
location #fallback {
proxy_intercept_errors on;
proxy_pass http://other-backend/internal/images/missing/?file_name=$uri;
}
It doesn't work right. No filename when proxying.
https://storage/bucket-media/large/

Remove query string from nginx

I'm having some trouble with an nginx.conf. I have a front end application which appends this code to the URL after a user logs in. I'm trying to have nginx remove this ?code=randomcode. I tried writing an nginx rewrite rule, but it is conflicting with another rule I have in place it seems. Below is the nginx.conf file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri$args $uri$args/ /index.html;
location /app1 {
try_files $uri$args $uri$args/ /index.html;
rewrite ^/app1(/.*) $1;
break;
}
location /app1/ {
set $args '';
rewrite ^/app1/(.*)$ /app1/$1 permanent;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
I am new to writing directives for nginx config files, so the logic may not make sense, but basically with the last rewrite rule written furthest down is causing all the JS files to report 404 (Not Found).
Any advice would be appreciated.

How to redirect nginx 404 error_page to homepage?

Here is an example of my server block:
server {
listen 80;
server_name website.com;
root /opt/bitnami/nginx/html/website;
index index.php index.html index.htm;
error_page 404 = #homepage;
location #homepage {
return 302 /;
}
location / {
try_files $uri $uri $uri/ #extensionless-php;
}
location #extensionless-php {
rewrite ^(.*)$ $1.php last;
}
include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
}
What happens is that pages that returned 404 still return 404 error, no redirect happends. What I'm trying to acomplish is to redirect 404 errors to homepage (or at least any other).
My nginx.conf file.
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location / {
proxy_intercept_errors on;
error_page 400 500 404 /;
}
}
}

Nginx `location /` does not match `/some_path`

Help me pls to configure nginx: I want nginx return index.html for all URLs like 10.10.256.142/, 10.10.256.142/some_path and 10.10.256.142/other_path/lala. Problem: currently it returns index.htmlonly for 10.10.256.142/ URL.
My current settings
listen 80;
server_name 10.10.256.142;
server_name_in_redirect off;
resolver 127.0.0.1;
location / {
error_page 405 =200 $uri;
root /some_path/project_dir;
index index.html index.htm;
}
location /websocket {
# ....
For me, simplest solution would be:
root /some_path/project_dir;
location / {
rewrite ^ /index.html break;
}
location /websocket/ {
# ...
}
Just to complete the answer above and return static assets I had to write
root /srv/www/betbull;
location / {
if ($uri !~ (/assets/.*)) { # do not return index.html instead of static assets
rewrite ^ /index.html break;
}
}
UPDATE:
Better solution:
location / {
try_files $uri $uri/ index.html$query_string
}

Nginx map directive always uses "default" with http param

I'm using Nginx map directive in order to retrieve the value of an http param and put it into another variable that will be used to do a basic auth with an ldap server (using nginx-auth-ldap).
The problem is that, according to my debug log, my map always chooses the default value.
Here is my configuration:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
map $args $groupe_ldap {
default "default_group";
include /opt/nginx/appli.conf;
}
ldap_server my_ldap_server {
url ldap://somehost:someport/ou=xxx,dc=yyy,....;
binddn "...";
binddn_passwd "...";
require group "cn=$groupe_ldap,...";
group_attribute member;
group_attribute_is_dn on;
require valid_user;
}
server {
error_log /opt/nginx/log/debug.log debug;
listen 8243;
server_name myhost;
more_clear_input_headers 'X-Forwarded-For';
auth_ldap "Forbidden";
auth_ldap_servers my_ldap_server;
if ($request_method !~ ^(GET|OPTIONS|POST)$ ) {
return 403;
break;
}
location ~ ^(/monitor(.*)) {
if ($arg_appli = "") {
return 403;
break;}
rewrite ^/monitor.* /$arg_appli?;
proxy_set_header Host myhost:myport;
root html;
index index.html;
break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}}
My appli.conf contains:
appli=1 ESB_SUPERADMIN;
The problem is that I always get default_groupe instead of ESB_SUPERADMIN when using this url: http://myhost:myport/monitor?appli=1.
Is something wrong on my configuration?
Thanks for your help.

Resources