Welcome! Log In Create A New Profile

Advanced

Clean-URL rewrite rule with nested "location" and alias directive

Ben Johnson
November 26, 2013 11:38AM
Hi!

I am attempting to serve a staging website from a directory that is
outside of the web-server's document root, while at the same time making
the site accessible at a URL that "appears" to be a subdirectory of the
top-level domain. (I have to do this so that the SSL certificate for the
TLD can be used for the staging site.)

This works as expected, with one major exception: "clean-URL" rewriting
does not work. In other words, the homepage (/stage/) loads correctly,
but all sub-pages return a 404. As soon as I attempt to add "rewrite"
directives for clean-URLs, the server either returns a 500 (redirect
cycle) or "Primary script unknown".

I have tried adding "rewrite_log on;" in the "server" block, just before
this configuration snippet (and reloading the nginx config), but the
directive seems to have no effect (no rewrite information is logged to
error.log). So, I am unable to determine what is happening here.

Here's the configuration snippet:

location ^~ /stage/ {
alias /var/www/example.com/private/stage/web/;

if ($scheme = http) {
return 301 https://$server_name$request_uri;
}

index index.php index.html index.htm;

location ~ ^/stage/(.+\.php)$ {
alias /var/www/example.com/private/stage/web/$1;

fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS on;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

# Trying to implement clean-URLs with this line,
# but it causes "primary script unknown" when using
# the "break" keyword, and redirect cycle when using
# the "last" keyword.
rewrite '^(.*)$' /stage/index.php?q=$1 break;
}
}

Any assistance with making this to work is hugely appreciated. Thanks in
advance!

-Ben

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Clean-URL rewrite rule with nested "location" and alias directive

Ben Johnson November 26, 2013 11:38AM

Re: Clean-URL rewrite rule with nested "location" and alias directive

Francis Daly November 26, 2013 11:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 161
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