atom feed29 messages in ru.sysoev.nginxRewrite help when files do NOT have a...
FromSent OnAttachments
pk899Jun 1, 2011 5:00 am 
António P. P. AlmeidaJun 1, 2011 6:05 am 
pk899Jun 1, 2011 6:22 am 
António P. P. AlmeidaJun 1, 2011 6:30 am 
Edho P AriefJun 1, 2011 6:32 am 
pk899Jun 1, 2011 7:02 am 
António P. P. AlmeidaJun 1, 2011 7:23 am 
pk899Jun 1, 2011 7:31 am 
António P. P. AlmeidaJun 1, 2011 7:53 am 
pk899Jun 1, 2011 8:29 am 
António P. P. AlmeidaJun 1, 2011 8:42 am 
pk899Jun 2, 2011 3:10 am 
António P. P. AlmeidaJun 2, 2011 11:53 am 
Marcos OrtizJun 2, 2011 12:27 pm 
Alexandr GomoliakoJun 2, 2011 1:12 pm 
Marcos Ortiz ValmasedaJun 2, 2011 1:17 pm 
pk899Jun 2, 2011 4:33 pm 
António P. P. AlmeidaJun 2, 2011 5:40 pm 
pk899Jun 2, 2011 6:21 pm 
António P. P. AlmeidaJun 2, 2011 6:44 pm 
pk899Jun 2, 2011 7:08 pm 
António P. P. AlmeidaJun 2, 2011 7:19 pm 
Antoine BonavitaJun 3, 2011 1:33 am 
pk899Jun 3, 2011 11:37 am 
pk899Jun 3, 2011 11:40 am 
António P. P. AlmeidaJun 3, 2011 11:46 am 
pk899Jun 3, 2011 9:26 pm 
António P. P. AlmeidaJun 4, 2011 9:08 am 
pk899Jun 4, 2011 10:51 pm 
Subject:Rewrite help when files do NOT have a ".php" extension
From:pk899 (ngin@nginx.us)
Date:Jun 1, 2011 5:00:16 am
List:ru.sysoev.nginx

Loving Nginx so far! So much faster and leaner than Apache.

Apologies for this yet another Rewrite rule help after so many threads, but one of domains has a special need and I am struggling with Rewrite rules.

The logic is simple:

1. For anything in /site folder, it should treat the static files as it is, but all else is php (file names don't have .php extension). Still further in this folder:

a. Within /site/private, it should be password protected b. Within /site/wordpress, there is a wordpress blog

2. For the main folder "/" all URLs should be directed to "/site/redirect".

Following is in URI examples, so that it easier to visualize:

(Lines starting with asterisks ** are already working)...

/abc ---> /site/redirect?u=abc /xyz ---> /site/redirect?u=xyz

** /site/abc ---> /site/abc (as PHP file) ** /site/xyz ---> /site/xyz (as PHP file)

** /site/1.gif ---> Served as it is, static ** /site/2.png ---> Served as it is, static

** /site/private/abc ---> Inside http auth, serve as PHP /site/private/ ---> Inside http auth, serve as PHP /site/private/index

/site/wordpress/.. ---> This is the usual wordpress thing.. The apache rules used to be: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /site/wordpress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /site/wordpress/index.php [L] </IfModule>

Here is what I have tried so far. I am almost there:

# SERVE CACHE STATIC FILES FIRST location ~* \.(xml|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|doc|xls|exe|ppt)$ { try_files $uri =404; expires max; access_log off; log_not_found off; }

# http://nginx.org/en/docs/http/converting_rewrite_rules.html location / { try_files $uri /site/redirect?u=$uri @fromphp =404; }

# FOR ALL THE PHP HANDLING location @fromphp { fastcgi_pass unix:/dev/shm/php5-fpm.MYDOMAIN.sock; fastcgi_index index; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }

# FOR THE REST OF THE WEBSITE location /site/ {

fastcgi_pass unix:/dev/shm/php5-fpm.MYDOMAIN.sock; fastcgi_index index; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;

location ~ /site/private/ { auth_basic "Restricted"; auth_basic_user_file /home/MYDOMAIN/.htpasswds/public_html/site/private/passwd; }

location ~ \.php$ { #NOTE: Set "cgi.fix_pathinfo = 0;" in php.ini fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/dev/shm/php5-fpm.MYDOMAIN.sock; fastcgi_intercept_errors on; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }

location ~ /site/wordpress/ { # Wordpress stuff try_files $uri $uri/ /site/wordpress/index.php?q=$uri&$args; if (-f $request_filename) { expires 30d; break; } if (-d $request_filename) { break; } if (!-e $request_filename) { rewrite ^/site/wordpress/(.+)$ /site/wordpress/index.php?q=$1 last; } }

}

Basically what is NOT working:

1. The main directory which is supposed to redirect to "/site/redirect?u=URI" 2. The Wordpress stuff is downloading a text file (with the full PHP code, which is scary)

Thanks for any ideas or pointers!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,202956,202956#msg-202956