Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have what I believe is a fairly standard fastcgi/php5-fpm setup using Unix socks, and the configuration file for my website (excuse the find&replace) is the following:

server {
                listen 80;

                access_log /srv/vhost/sites/example/logs/access.log;
                error_log /srv/vhost/sites/example/logs/error.log;

                root /srv/vhost/sites/example/public_html;
                index index.php index.html index.htm;

                location / {
                    index index.php;
                    try_files $uri $uri/ @wikka;

                location @wikka {
                    rewrite ^(.*/[^\./]*[^/])$ $1/ last;
                    rewrite ^(.*)$ /wikka.php?wakka=$1 last;

                location ~ \.php$ {
                  try_files $uri = 404;

                  fastcgi_split_path_info ^(.+\.php)(/.+)$;

                  include fastcgi_params;
                  fastcgi_param  SCRIPT_FILENAME /srv/vhost/sites/example/public_html$fastcgi_script_name;
                  fastcgi_index  index.php;
                  fastcgi_pass   unix:/etc/nginx/sockets/example.sock;

I cannot seem to ever get it to rewrite /xxx to wikka.php?wakka=xxx.

I usually always get 502 BAD GATEWAY on these rewrite attempts, and the logs show nearly the same thing each time:

[error] 19289#0: *6 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:, server:, request: "GET /Home HTTP/1.1", upstream: "fastcgi://unix:/etc/nginx/sockets/example.sock:", host: ""

Do you know what can be happening? Do you know how to rewrite the simple example as above in nginx? It appears people have asked for similar information (WikkaWiki is the name, here: nginx rewrite for wikkawiki but were not successful)

I've tried various @locations, or adding the rewrite to various places with last; or break; at the end often ending up in redirect loops.

I always upload the new configuration and SIGHUP (or restart via init.d) nginx, and before test with nginx -t to ensure it is at least valid if you require that information.

share|improve this question
Are you sure PHP-FPM is up & running & available through the unix socket? 502 sometimes arise when backend is not available. – petermolnar Feb 20 '12 at 10:06

Try recopying everything inside the Location ~ .php block into Location @wikka block.

share|improve this answer
Link-only answers are strongly discouraged. Please edit your answer and post content here, linking to external sources if needed. – EEAA Feb 3 '13 at 3:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.