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

Here's my NGINX config (no apache, just php-fpm):

user  nginx;
worker_processes  1;
error_log /usr/local/nginx/logs/error.log notice;
pid       /var/run/;

events  {
        worker_connections      384;

http    {
        include          mime.types;
        default_type  application/octet-stream;
        access_log          off;
    server_tokens       off;
        sendfile                 on;
        tcp_nopush           on;
    tcp_nodelay             off;
    client_max_body_size     8M;
    client_body_timeout      30;
    client_header_timeout    15;
    keepalive_timeout     15 65;
    send_timeout             30;

gzip on;
    gzip_static on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 9;
    gzip_buffers 32 4k;
    gzip_http_version 1.0;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    upstream php-fpm-sock {
    server unix:/var/run/php-fpm.sock;

server  {
        listen          80;
        index           index.php index.html;
        root            /usr/local/nginx/html;
    error_page      404 index.php;

        if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;

        location ~* \.(?:jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
        expires 1y;
        log_not_found off;

        location / {
    try_files $uri $uri/ /index.php?q=$uri;

    location /blog {
        try_files $uri $uri/ /index.php?$uri&$args;

        location ~ \.php$ {
         fastcgi_index  index.php;
                try_files $uri =404;
         fastcgi_pass   php-fpm-sock;
             fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
             include        fastcgi_params;
         fastcgi_connect_timeout    15;
         fastcgi_send_timeout   30;
         fastcgi_read_timeout   15;
         fastcgi_buffer_size    8k;
         fastcgi_buffers         32 8k;

I thought maybe it was godaddy doing some sort of forwarding but I moved DNS from Godaddy to AWS Route 53 and STILL if I type it forwarded to 301's to

My Route 53 dns:   3600    A

* 3600    CNAME

What causing this redirect?


share|improve this question
Please provide the actual domain you're working with, so people can test it themselves. Obfuscation is frustrating. – womble Mar 18 '12 at 1:50

2 Answers 2

up vote 2 down vote accepted

nginx isn't redirecting - especially not sending the 301 response code that you're seeing. The code that's running in PHP is almost certainly the culprit.

Please provide information about what's running in PHP code - nginx is not the problem.

share|improve this answer
THANK YOU! Ok I guess my focus was on nginx too much. Its a setting in the PHP script's config. I changed to to and it removes the www and reverted and it adds the I was looking into using nginx to do the 301 but seems the script is sending 301 anyway. Plus, when I compiled nginx I did not enable rewrite so that's why I thought maybe it was some sort of bug lol – Hayden Mar 18 '12 at 9:09

I have noticed that in most web browsers if they can't make a connection using, then they will automatically (and near instantaneously) jump to Make sure your server is actually answering the request for

Do the following to test, and please leave a comment with results (this assumes the use of a Linux workstation, maybe someone else can post a Windows/Mac version):

Make sure the domain resolves when used by itself:


Make sure the web server is actually listening:

telnet 80

See where the web server sends us when requesting the index file:


Good luck!

share|improve this answer
According to response headers are: HTTP/1.1 301 Moved Permanently Server: nginx Date: Sun, 18 Mar 2012 05:25:06 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Keep-Alive: timeout=65 Set-Cookie: session_id=xxxxxxxxxxxxxxx; path=/;; httponly Location: – Hayden Mar 18 '12 at 5:27
nslookup Server: Address: Non-authoritative answer: Name: Address: – Hayden Mar 18 '12 at 5:30
WGET = Resolving Connecting to||:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Cookie coming from attempted to set domain to Location: [following] --2012-03-18 05:30:55-- Resolving Connecting to||:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: “index.html”[ <=>] 97,543 --.-K/sin 0.008s (11.9 MB/s) - “index.html” saved [97543 – Hayden Mar 18 '12 at 5:34

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.