Convert Apache rewrite to NGinx

GASPARD kévin list-reader at koshie.fr
Sun Mar 3 12:52:48 UTC 2013


Hi,

Using nginx 1.2.1 on Debian Wheezy 64 bits.

My wordpress need rewrite, it gave me this:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


I've tried to convert it with this website: http://winginx.com/htaccess.
The result is:


# nginx configuration

location / {
     if (!-e $request_filename){
       rewrite ^(.*)$ /index.php break;
     }
}


I've put it into /etc/nginx/conf.d/doinalefort.fr.conf like this:


server {
           listen      80;
           listen      443 ssl;
           # server_name     176.31.122.26;
           server_name     doinalefort.fr www.doinalefort.fr;
           root        /var/www/doinalefort.fr;

           msie_padding on;

           ssl_session_timeout  5m;

           ssl_protocols  SSLv2 SSLv3 TLSv1;
           ssl_ciphers  HIGH:!aNULL:!MD5;
           ssl_prefer_server_ciphers   on;

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

           index         index.php;
           fastcgi_index index.php;

           client_max_body_size      8M;
           client_body_buffer_size 256K;

           location ~ \.php$ {
                   include fastcgi_params;

                   # Assuming php-fastcgi running on localhost port 9000
                   fastcgi_pass unix:/var/run/php5-fpm.sock;
                   fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;

                   fastcgi_connect_timeout 60;
                   fastcgi_send_timeout 180;
                   fastcgi_read_timeout 180;
                   fastcgi_buffer_size 128k;
                   fastcgi_buffers 4 256k;
                   fastcgi_busy_buffers_size 256k;
                   fastcgi_temp_file_write_size 256k;
                   fastcgi_intercept_errors on;

           location / {
                   if (!-e $request_filename){
                   rewrite ^(.*)$ /index.php break;
                   }
}

           }
}

And restarted nginx, but it give me this error:


Restarting nginx: nginx: [emerg] location "/" is outside location "\.php$"  
in /etc/nginx/conf.d/doinalefort.fr.conf:44
nginx: configuration file /etc/nginx/nginx.conf test failed


And idea?

Cordially, Koshie


-- 
Sorry for my english, I'm trying the best in each e-mail writing. Tell me  
if I'm not clear enough.
This mail account is only for list reading, to contact me send an e-mail  
at kevingaspard at koshie.fr



More information about the nginx mailing list