Welcome! Log In Create A New Profile

Advanced

help with rewrites

Posted by noob 
help with rewrites
June 16, 2011 05:12AM
Hello,

Could you please help me transport these mod rewrites into nginx?

RewriteRule ^(.*)$ %{SERVER_NAME}$1 [C]

RewriteCond %{SERVER_NAME} ^(.*)\.domain\.com$

RewriteRule ^([a-z0-9-]+)\.domain\.com/(.*)$ /home/www/$1/$2 [L]

cannot make it work in nginx :(
Re: help with rewrites
July 17, 2011 12:27PM
Hi

try the following:

if ($http_host ~ \.domain\.com$) {
rewrite ^(?!/$http_host/)(.*)$ /$http_host$1;
rewrite ^/([^.]+)\.domain\.com/(.*)$ /home/www/$1/$2 last;
}

Andrejs
Re: help with rewrites
October 13, 2011 08:54AM
Hi Andrejs,

Thank you for you replay.

It seems that rewrite works, but somehow nginx doubles it, i.e.:
[error] 32225#0: *1 open() "/home/www/subdomain/home/www/subdomain/index.php" failed (2: No such file or directory)

it should be just /home/www/subdomain/index.php

i tried to play in many ways for example instead of location { root / }, i would change location { root /home/www }.
then i get:

32244#0: *1 "/home/www/home/www/subdomain/index.php" is not found

it adds ROOT to the beginning of rewrite, is there a possibility to not add root in the beginning?

you could say "remove /home/www from rewrite rule, just leave the rest"
ok, lets do it:

rewrite ^/([^.]+)\.domain\.com/(.*)$ /$1/$2 last;

what i get is:

[error] 32251#0: *1 open() "/home/www/subdomain/subdomain/index.php" failed

it then doubles the left part of it.

in such a way i played variously with config changing paths, locations etc, but it never hits the target :)

in apache though, it just redirects to where i want without looking for "root".

any suggestions?
Re: help with rewrites
October 13, 2011 07:39PM
Hello,

Please attach your entire nginx.conf.

Andrejs
Re: help with rewrites
October 17, 2011 11:11AM
Hi,

here is attached .conf
(actual domain changed to changedtoexample.com)


the log it produces for example on https://temp.changedtoexample.com is:
[error] 20364#0: *1 open() "/home/www/crm/temp/home/www/crm/temp/index.php" failed (2: No such file or directory)
Attachments:
open | download - ng.conf (2.4 KB)
Re: help with rewrites
October 17, 2011 01:38PM
Hello,

First, what I noticed in your nginx.conf is that root directive does not specify the full document root path. I think the complete path must be specified. I would suggest moving "root" in to the server level, say just below server_name.

Second, I think you don't have to repeat declaring root in each location. Usually, it should remain the same for the virtual host, just like Apache's DocumentRoot directive.

Third, I think fastcgi_pass must come as the last statement, and definitely after fastcgi_params. I would suggest the following location configuration:

location / {
index index.html index.htm index.php;
}

location ~ \.php$ {
# abort with 404 if attempting to call a non-existing PHP script
try_files $fastcgi_script_name =404;

# fastcgi_params already contains SCRIPT_FILENAME set to "$document_root$fastcgi_script_name"
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 138
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready