0

I have a server running Magento E-commerce application and it is running using Nginx. Recently I installed a Wordpress blog under document root like this: http://example.com/blog When I/m dealing with permalink of wordpress I find out try_files directive inside of my config file is not working properly. Here is my config file:

server {
    listen www.xxx.com:80;
    server_name www.xxx.com;
    root /home/abc/www;
    access_log /home/abc/log/access.log;
    error_log /home/abc/log/error.log;
    index index.php index.html index.htm;

    if ($request_uri ~ " ") {
        return 444;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 7d;
    }

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

    location ~* \.(html|htm)$ {
        expires 1d;
    }

    location / {
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        #expires 30d;                  ## Assume all files are cachable
    }

    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

    location /var/export/ {                ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd;     ## See /etc/nginx/htpassword
        autoindex            on;
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    if (!-e $request_filename) { rewrite / /index.php last; }

    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        include fastcgi_params;
    }

}

I tried to remove `if (!-e $request_filename) { rewrite / /index.php last; } but after that all my links on frontend went to 404.

Another thing is I have a staging site on the same server and it works fine after I remove that line of code. I'm very confused and don't know what goes wrong here. Could anyone help? I will post more details if needed. Just let me know. Thanks a lot.

Xavier Lucas
  • 13,095
  • 2
  • 44
  • 50
mike
  • 1
  • Remove this if and use try_files inside a location instead. You have unescaped dots in your regexs too. You probably also need to add your @handler location's rewrite a `last` flag too. – Xavier Lucas Dec 30 '14 at 13:11
  • Thanks Xavier. There is a try_files in "location /" already. I tried to remove that if code and I think try_files will take its place but it doesn't. BTW, what you mean by "unescaped dots"? Could you be more detail? – mike Dec 31 '14 at 06:51

0 Answers0