Nginx non www to www problem!


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=)" />

Here is my nginx.conf file!

        listen       80;
                 rewrite ^(.*)$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) {

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!


1 Reply

anyway now i got this working! :)


Please enter an answer

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] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct