Welcome! Log In Create A New Profile

Advanced

[REWRITE] Only 3 rules...

Posted by Epicar 
[REWRITE] Only 3 rules...
April 26, 2010 02:31PM
Hi everybody !

I decided to use NginX as a reverse proxy for delivery static files... and it seems to perform very well :)

I have some difficulties on migrating 3 rewrite rules.
The images like "^vehicules/blabla/blablabla....blabla.jpg" need to be rewrited, just before being served by NginX.
Simple, isn'it ?

Actually, these rules are not intercepted by NginX... and are forwarded to Apache :(


Here is my configuration file :

[code]

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
# General parameters
include mime.types;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 64;

# Define a log format
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$gzip_ratio"'
'"$http_user_agent" "$http_x_forwarded_for"';

# Path to store logs
access_log off;#logs/www.epicar.com-access.log main;
error_log logs/www.epicar.com-error.log;


# TCP parameters
keepalive_timeout 120;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;


# Compression parameters
gzip on;
gzip_vary on;
gzip_comp_level 5;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon application/x-javascript application/xml application/xml+rss text/javascript; #text/html

# Define a cluster of servers
upstream mongrel {
server 127.0.0.1:8080;
#server 127.0.0.1:8080;
#server 127.0.0.1:8080;
}

# Server
# ----------------------------------------------------------------------------
server {
# Server - General parameters
listen 80;
server_name www.dtruffaut.epicar.com img0.dtruffaut.epicar.com img1.dtruffaut.epicar.com img2.dtruffaut.epicar.com;
root "C:/Program Files/Wamp/www/epicar";
#charset utf-8;

# Server - Static files
location ~* ^.+.(jpg|jpeg|gif|png|ico|txt|srt|swf)$ {
# Existing static files are directly distributed
if (-f $request_filename) {
#expires 30d;
break;
}

# I'm blocked here : These rewrite don't seem to execute, and images don't load
# If I delete the break instruction, they're forwarded to Apache, which have the rewrite and load them,
# but that's not the expected result... I want this files to be served by NginX !
# Rewrites are :
# RewriteRule ^vehicule/([a-z\-]+)/[0-9a-z\-]+-neuf-1-([0-9a-z_]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/$1/$2.jpg [L]
# RewriteRule ^vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-photo-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$4/distributor/$1/$2_$3.jpg [L]
# RewriteRule ^vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/distributor/$1/$2.jpg [L]
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

rewrite ^vehicule/([a-z\-]+)/[0-9a-z\-]+-neuf-1-([0-9a-z_]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/$1/$2.jpg last;
rewrite ^vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-photo-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$4/distributor/$1/$2_$3.jpg last;
rewrite ^vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/distributor/$1/$2.jpg last;

break;

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# Server - Dynamic files : forwarded to Apache
location / {
proxy_pass http://mongrel;
}

# Server - PhpMyAdmin : forwarded to Apache
location /phpmyadmin {
proxy_pass http://mongrel/phpmyadmin;
}

# Server - Errors : forwarded to Apache
error_page 404 /erreur/404.html;
location = erreur/404.html {
proxy_pass http://mongrel/erreur/404.html;
}
error_page 500 /erreur/500.html;
location = erreur/500.html {
proxy_pass http://mongrel/erreur/500.html;
}
error_page 501 /erreur/501.html;
location = erreur/501.html {
proxy_pass http://mongrel/erreur/501.html;
}
error_page 502 /erreur/502.html;
location = erreur/502.html {
proxy_pass http://mongrel/erreur/502.html;
}
error_page 503 /erreur/503.html;
location = erreur/503.html {
proxy_pass http://mongrel/erreur/503.html;
}

#location ~ /\.ht {
# deny all;
#}
}

# Default server
# ----------------------------------------------------------------------------
# Redirects all wrong subdomains on www
server {
listen 80 default_server;
server_name _;
rewrite ^ http://www.dtruffaut.epicar.com$request_uri?;
}

}

[/code]

Is something wrong ?



Edited 1 time(s). Last edit at 04/26/2010 02:35PM by Epicar.
Re: [REWRITE] Only 3 rules...
April 27, 2010 05:08AM
Fixed, I got it :

[code]
# Server - Static files
location ~* ^.+.(jpg|jpeg|gif|png|ico|xml|txt|swf|xls|csv)$ {
rewrite ^/vehicule/([a-z\-]+)/[0-9a-z\-]+-neuf-1-([0-9a-z_]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/$1/$2.jpg last;
rewrite ^/vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-photo-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$4/distributor/$1/$2_$3.jpg last;
rewrite ^/vehicule/[a-z\-]+/[0-9a-z\-]+-[1-3]-([0-9]+)-([0-9]+)-([a-z]+)\.jpg$ /tmp/cache/cars/$3/distributor/$1/$2.jpg last;
# Existing static files are directly distributed
if (-f $request_filename) {
#expires 30d;
break;
}
}
[/code]

You just have to write a / after the ^ symbol.

Here is the link which helped me :
http://www.anilcetin.com/convert-apache-htaccess-to-nginx/


Epicar
http://www.epicar.com/ :)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 335
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready