Switching to nginx: php and rewrite rules from apache

Hello list,

I’m moving a bunch of sites from Apache to nginx 1.5.13 :).

Everything went fine for the static ones and for the sites under wp or
joomla. I have one site in php developped by the customer that seemed
ok till I discovered that it has a subdirectory with its own .htacess
file. Trying to add the rewriting rules makes the php “dead”, only in
the cited subdirectory.

Here is my config:

server {
listen 212.45.144.216:80 default_server;
server_name new.assirm.it test.assirm.it;
access_log /dati/log/http/assirm/access.log;
error_log /dati/log/http/assirm/error_new.log;

    rewrite_log on;

    #charset koi8-r;

    location ~ \.php$ {
        root /dati/httpd/web_assirm/sito_nginx;
        fastcgi_pass 127.0.0.1:9004;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi.conf;
    }

    location / {
        root   /dati/httpd/web_assirm/sito_nginx;
        index  index.html index.htm index.php home.html 

welcome.html;

try_files $uri $uri/ /index.php?$args;

    rewrite ^/ultime-news.php$ /archivio-news.php?last=1 ;

rewrite ^/(.)_news(.).htm$ /news.php?id=$2 ;
rewrite ^/(.)_ev(.).htm$ /evento.php?id=$2 ;
rewrite ^/(.)_att(.).htm$ /attivita.php?id=$2 ;
rewrite ^/(.)_k(.).htm$ /pagina.php?k=$2 ;
rewrite ^/(.)_sk(.).htm$ /stampa-contenuto.php?k=$2 ;
rewrite ^/(.)_sn(.).htm$ /stampa-news.php?id=$2 ;
rewrite ^/(.)_a(.).htm$ /associato.php?id=$2&$args ;
rewrite ^/(.)_p(.).htm$ /mypost.php?id=$2&$args ;
rewrite ^/ricerca-(.*).htm$ /risultati.php?s=$1&goo=1 ;
rewrite ^/privacy.php$ /pagina.php?k=privacy ;
}

    location ^~ /en/ {
        rewrite ^/en/ultime-news.php$ /en/archivio-news.php?last=1 

break;
rewrite ^/en/(.)_news(.).htm$ /en/news.php?id=$2 break;
rewrite ^/en/(.)_ev(.).htm$ /en/evento.php?id=$2 break;
rewrite ^/en/(.)_att(.).htm$ /en/attivita.php?id=$2 break;
rewrite ^/en/(.)_k(.).htm$ /en/pagina.php?k=$2 break;
rewrite ^/en/(.)_sk(.).htm$ /en/stampa-contenuto.php?k=$2
break;
rewrite ^/en/(.)_sn(.).htm$ /en/stampa-news.php?id=$2
break;
rewrite ^/en/(.)_a(.).htm$ /en/associato.php?id=$2&$args
break;
rewrite ^/en/(.)_p(.).htm$ /en/mypost.php?id=$2&$args
break;
rewrite ^/en/(.)_wit(.).htm$ /en/wit.php?c=$2&$args break;
rewrite ^/en/ricerca-(.*).htm$ /en/risultati.php?s=$1&goo=1 break;
rewrite ^/en/privacy.php$ /en/pagina.php?k=privacy break;
}
#error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }


}

What did I have wrong?

Many thanks to all,

Luciano.

/"\ /Via A. Salaino, 7 - 20144 Milano (Italy)
\ / ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
X AGAINST HTML MAIL / E-MAIL: [email protected]
/ \ AND POSTINGS / WWW: http://www.lesassaie.IT/

On Sat, Jun 07, 2014 at 10:50:05AM +0200, Luciano Mannucci wrote:

Hi there,

I have one site in php developped by the customer that seemed
ok till I discovered that it has a subdirectory with its own .htacess
file. Trying to add the rewriting rules makes the php “dead”, only in
the cited subdirectory.

You use “location” (http://nginx.org/r/location) and “rewrite”
(http://nginx.org/r/rewrite) with the “break” flag.

Based on the documentation, I guess that you will want to include within
your “/en/” location, some configuration which tells nginx how you want
php requests to be handled.

What did I have wrong?

You left out some useful information:

  • what request do you make?

  • what response do you get?

  • what response do you want?

    f

    Francis D. [email protected]

On Sat, 7 Jun 2014 10:08:54 +0100
Francis D. [email protected] wrote:

On Sat, Jun 07, 2014 at 10:50:05AM +0200, Luciano Mannucci wrote:

Hi there,

What did I have wrong?

You left out some useful information:

  • what request do you make?
    new.assirm.it/en/
  • what response do you get?
    The index.php page source.
  • what response do you want?
    The php interpreted result.

Many thanks again,

Luciano.

/"\ /Via A. Salaino, 7 - 20144 Milano (Italy)
\ / ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
X AGAINST HTML MAIL / E-MAIL: [email protected]
/ \ AND POSTINGS / WWW: http://www.lesassaie.IT/

On Sat, Jun 07, 2014 at 12:08:05PM +0200, Luciano Mannucci wrote:

On Sat, 7 Jun 2014 10:08:54 +0100
Francis D. [email protected] wrote:

Hi there,

  • what request do you make?
    new.assirm.it/en/
  • what response do you get?
    The index.php page source.
  • what response do you want?
    The php interpreted result.

So, within your

    location ^~ /en/ {

add something like

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9004;
    }

so that nginx knows to handle this request the way you want it to.

(If you have no other configuration, the nginx default is “serve the
file from the file system”.)

f

Francis D. [email protected]

On Sat, 7 Jun 2014 11:39:55 +0100
Francis D. [email protected] wrote:

add something like

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9004;
    }

so that nginx knows to handle this request the way you want it to.
Works! :slight_smile: :slight_smile:

I had to add few other things (it was looking for index.html instead
of .php) and now it seems fine.

Maaaany thanks,

Luciano.

/"\ /Via A. Salaino, 7 - 20144 Milano (Italy)
\ / ASCII RIBBON CAMPAIGN / PHONE : +39 2 485781 FAX: +39 2 48578250
X AGAINST HTML MAIL / E-MAIL: [email protected]
/ \ AND POSTINGS / WWW: http://www.lesassaie.IT/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs