Nginx non www to www problem!

Hello,

I have nginx+memcached+wp supercache running on my blog!

How ever I performed non www to www redirect in /usr/local/nginx/conf/nginx.conf

And I have inserted wp supercache code inside to this (red color) and its working properly!

How ever after adding www redirect and restarting nginx it shows this error. It seems like error is on wp supercache code but it works properly. And non www redirect is not working as it should

~~![](<URL url=)http://i53.tinypic.com/f0nhix.jpg" />

Here is my nginx.conf file!

server
        {
        listen       80;
                server_name www.ruchirablog.com ruchirablog.com;
                 rewrite ^(.*) http://www.ruchirablog.com$1 permanent;
   }

                index index.html index.htm index.php;
                root  /home/wwwroot;

               location / {
# enable search for precompressed files ending in .gz
# nginx needs to be complied using .-with-http_gzip_static_module
# for this to work, comment out if using nginx from aptitude

# if the requested file exists, return it immediately
if (-f $request_filename) {
break;
}

set $supercache_file '';
set $supercache_uri $request_uri;

if ($request_method = POST) {
set $supercache_uri '';
}

# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}

if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}

# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}

# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
rewrite ^(.*)$ $supercache_file break;
}

# all other requests go to Wordpress
if (!-e $request_filename) {
rewrite . /index.php last;
}
}

                location ~ .*\.(php|php5)?$
                        {
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fcgi.conf;
                        }
       location / {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
         }
        }

                location /status {
                        stub_status on;
                        access_log   off;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
                access_log  /home/wwwroot/logs/access.log  access;
    }
include vhost/*.conf;
}

After I restart the nginx it shows the error that pictured above!

Please help me to resolve this as my current non www to www redirect is not working!

Thanks~~

1 Reply

anyway now i got this working! :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct