Welcome! Log In Create A New Profile

Advanced

Re: Regular Expression global redirect

António P. P. Almeida
February 26, 2012 07:42PM
On 27 Fev 2012 00h39 CET, nginx-forum@nginx.us wrote:

> I still cant seem to get this working. I upgraded my PCRE libraries
> and recompiled/reinstalled a fresh nginx 1.0.12
>
> # pcrecheck
> PCRE version 8.21 2011-12-12
>
> Here is my server sections. Notice I have 2 server sections...the
> 1st section catches the WWW site and redirects it to the 2nd,
> non-www...right? I'm still getting: nginx: [emerg] unknown "domain"
> variable
>
> server {
> listen 80;
> server_name ^~www\.(?<domain>.*)$;
> return 301 http://$domain;
> }
>
> server {
> listen 80;
> server_name ^~(?<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;
> location / {
> proxy_pass http://websites;
> }
> }
>
> When I try it with the P, everything (www and nonwww) get a white
> 301 nginx page: server { listen 80; server_name
> ^~www\.(?P<domain>.*)$; return 301 $scheme://$domain$request_uri;; }
>
> server {
> listen 80;
> server_name _;
> location / {
> proxy_pass http://websites;
> }
> }
>
> I tried making server_name in the 2nd block:
> server_name ^~(?P<domain_name>[^\.]*)\.(?<tld>[^\.]*)$;
>
> but I get this:
> nginx: [emerg] invalid server name or wildcard
> "^~(?p<domain_name>[^\.]*)\.(?<tld>[^\.]*)$" on 0.0.0.0:80
> (fyi, the error has a lowercase p, server_name has it capitalized)
>
> Is there some other dependency I'm missing or am I just mangling the
> syntax?

Oops. I erroneously switched the '^' and '~'. It's ~^ not ^~. Solly :(

Ok. It seems that your PCRE library has problems with the non P syntax
for named captures. So you cannot mix both.

server {
listen 80;
server_name ~^www\.(?P<domain>.*)$;
return 301 $scheme://$domain$request_uri;
}

server {
listen 80;
server_name ~^(?P<domain_name>[^\.]*)\.(?P<tld>[^\.]*)$;
location / {
proxy_pass http://$domain_name.$tld;
}
}

This should work [1].

--- appa

[1] http://nginx.org/en/docs/http/server_names.html

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

Regular Expression global redirect

altiamge February 25, 2012 10:59PM

Re: Regular Expression global redirect

António P. P. Almeida February 25, 2012 11:42PM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 01:22AM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 09:40AM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 09:44AM

Re: Regular Expression global redirect

altiamge February 26, 2012 02:27AM

Re: Regular Expression global redirect

altiamge February 26, 2012 06:39PM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 02:30AM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 07:22PM

Re: Regular Expression global redirect

altiamge February 26, 2012 07:26PM

Re: Regular Expression global redirect

altiamge February 26, 2012 08:15PM

Re: Regular Expression global redirect

António P. P. Almeida February 26, 2012 07:42PM

Re[2]: Regular Expression global redirect

Max February 27, 2012 01:34AM

Re: Re[2]: Regular Expression global redirect

António P. P. Almeida February 27, 2012 05:14AM

Re[4]: Regular Expression global redirect

Max February 27, 2012 10:48PM

Re: Re[4]: Regular Expression global redirect

António P. P. Almeida February 28, 2012 07:12AM

Re: Regular Expression global redirect

Edho Arief February 26, 2012 01:12AM

Re: Regular Expression global redirect

Mark Alan February 26, 2012 07:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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