Simple URI redirection / alias in Nginx…

Please, how can I make this simple operation:

I wish that every requests for uris like:
http://example.com/adm
or:
http://example.com/adm
Goes to the wordpress login page:
wordpress/wp-login.php
(The wordpress installation is inside the folder “wordpress”).

I’ve tried:

location /adm/ { alias wordpress/wp-login.php; }
location /adm { alias wordpress/wp-login.php; }

and:

rewrite ^/adm$ wordpress/wp-login.php;

But with no success…

Just in case someone asks, this is my serve conf. file:

server {
server_name www.example.com;
rewrite ^ http://example.com$request_uri? permanent;
}

server {
server_name example.com;

access_log /var/log/nginx/example.com.access;
error_log /var/log/nginx/example.com.error;

root /var/www/example.com;

index index.htm index.php;

location / {try_files $uri /wp$uri/ /wordpress/index.php$args;}

location ~ .php$ {
  try_files $uri =404;
  #fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include /etc/nginx/fastcgi_params;
}

location = /favicon.ico {log_not_found off;access_log off;}
location = /robots.txt {allow all;log_not_found off;access_log off;}
location ~ /\. {deny all;access_log off;log_not_found off;  }

}

Posted at Nginx Forum:

On Mon, May 30, 2011 at 09:40:09AM -0400, atipico wrote:

I’ve tried:
Just in case someone asks, this is my serve conf. file:
error_log /var/log/nginx/example.com.error;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

location = /favicon.ico {log_not_found off;access_log off;}
location = /robots.txt {allow all;log_not_found off;access_log off;}
location ~ /\. {deny all;access_log off;log_not_found off;  }

}

location = /adm/ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
/var/www/example.com/wordpress/wp-login.php
include /etc/nginx/fastcgi_params;
}

location = /adm {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
/var/www/example.com/wordpress/wp-login.php
include /etc/nginx/fastcgi_params;
}


Igor S.

I have a similar issue.

Do we need separate location directives for each and every possible
path, or can we do some “rewrite” inside location for the main / root
folder? For example:

location = / {

rewrite rules come here…

rewrite “^/adm$” “/wordpress/wp-login.php”;

fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME
/var/www/example.com/wordpress/wp-login.php
include /etc/nginx/fastcgi_params;

}

To me this is cleaner, but want to make sure that this is not the less
desirable way?

Thanks.

Posted at Nginx Forum:

I meant this:

location / {

Not “location = / {” of course.

Thanks!


rewrite “^/adm$” “/wordpress/wp-login.php”;
To me this is cleaner, but want to make sure that
this is not the less desirable way?

Thanks.

Posted at Nginx Forum:

On Mon, May 30, 2011 at 07:03:17PM -0400, atipico wrote:

Thank you Igor.

So what is the difference among doing what you told and this?
rewrite ^/adm$ /wp/wp-login.php;

Configuration maintenance. If you will not use rewrites and regex
locations,
then you can easy change large configuration.

Isn’t it the case of usind the “alias”?

“alias” is for static files, but not scripts.


Igor S.

I know it is a bit far from the original topic but, I have a site with
just one file: index.htm witch have some ajax linked to php files. I’d
like to make thouse php files only accessable via ajax (post and get)
coming from this index file and block access to all files but the
index.htm. Is it possible in Nginx?

Posted at Nginx Forum:

Thank you Igor.

So what is the difference among doing what you told and this?
rewrite ^/adm$ /wp/wp-login.php;

Isn’t it the case of usind the “alias”?

Thank you onc more,
Rogerio.

Posted at Nginx Forum: