# Help with NGINX config for Magento

**URL:** <https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446>\
**Category:** NGINX\
**Created:** [March 20, 2010, 8:36am UTC](https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446 "2010-03-20T08:36:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbuckler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/85f322/32.png) [@hbuckler](https://www.ruby-forum.com/u/hbuckler)\
**Post date:** [March 20, 2010, 8:36am UTC](https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446/1 "2010-03-20T08:36:42Z")

</div>

Hi,

I have seen a similar situation here but the solution didn’t work for  
me. I am getting a ‘NO INPUT FILE SPECIFIED’ and my permanent redirect  
from non-www to www doesn’t seem to work.

Here is my conf file at /etc/nginx/nginx.conf

user nginx nginx;  
worker\_processes 6;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
   log_format main '$remote_addr - $remote_user [$time_local]

```

$request ’  
'"$status"  
$body\_bytes\_sent"$http\_referer" ’  
‘"$http\_user\_agent"  
“$http\_x\_forwarded\_for”’;

```
   access_log /var/log/nginx/access.log main;
   sendfile on;
   tcp_nopush on;
   tcp_nodelay off;
   gzip on;
   gzip_http_version 1.0;
   gzip_comp_level 2;
   gzip_proxied any;
   gzip_types text/plain text/css application/x-javascript

```

text/xml application/xml application/xml+rss text/javascript

```
   # fastcgi nodes
   upstream backend {
          server unix:/tmp/fcgi.sock;
   }

   server {
   listen 80;
   server_name www.openfreeze.com;
   root /var/www/html;
   client_max_body_size 50M;
   # protection (we have no .htaccess)
   location ~

```

(^/magento/(app/|includes/|lib/|/pkginfo/|var/|report/config.xml)|/.svn/|/.hta.+)  
{  
deny all;  
}

```
   # vhost specific access log
   access_log /var/log/nginx/vhost.access.log main;

   # this rewrites all the requests to the maintenance.html
   if (-f $document_root/system/maintenance.html) {
          rewrite ^(.*)$ /system/maintenance.html last;
          break;
   }

   # handle all .php files, /downloader and /report
   location ~ (\.php|/downloader/?|/report/?)$ {
          if ($request_uri ~ /(downloader|report)$){
                 # no trailing /, redirecting
                 rewrite ^(.*)$ $1/ permanent;

    }

    fastcgi_index index.php;
   include /etc/nginx/fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

   if (-e $request_filename) { # check if requested path exists
   fastcgi_pass backend;
   }

   }

   # magento
   location / {
          # set expire headers
          if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") {
                 expires max;
          }

   # set fastcgi settings, not allowed in the .if. block
   include /etc/nginx/fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root/index.php;
   fastcgi_param SCRIPT_NAME /index.php;

   # rewrite - if file not found, pass it to the backend
   if (!-f $request_filename) {
          fastcgi_pass backend;
          break;
   }
   }

```

}  
}

HERE IS MY FASTCGI\_PARAMS /etc/nginx/fastcgi\_params

fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;

fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;  
fastcgi\_param REQUEST\_URI $request\_uri;  
fastcgi\_param DOCUMENT\_URI $document\_uri;  
fastcgi\_param DOCUMENT\_ROOT $document\_root;  
fastcgi\_param SERVER\_PROTOCOL $server\_protocol;

fastcgi\_param GATEWAY\_INTERFACE CGI/1.1;  
fastcgi\_param SERVER\_SOFTWARE nginx/$nginx\_version;

fastcgi\_param REMOTE\_ADDR $remote\_addr;  
fastcgi\_param REMOTE\_PORT $remote\_port;  
fastcgi\_param SERVER\_ADDR $server\_addr;  
fastcgi\_param SERVER\_PORT $server\_port;  
fastcgi\_param SERVER\_NAME $server\_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi\_param REDIRECT\_STATUS 200;

Any help will be really appreciated.

---

<div class="post-metadata">

**Author:** ![hbuckler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/85f322/32.png) [@hbuckler](https://www.ruby-forum.com/u/hbuckler)\
**Post date:** [March 20, 2010, 12:25pm UTC](https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446/2 "2010-03-20T12:25:21Z")

</div>

On 20-3-2010 8:36, Howard Barntt wrote:

> Any help will be really appreciated.

Hi Howard,

Untested, but I ran into this config recently:  
[http://www.magentocommerce.com/boards/viewthread/7931/](http://www.magentocommerce.com/boards/viewthread/7931/)

Good luck.

Wouter

---

<div class="post-metadata">

**Author:** ![hbuckler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/85f322/32.png) [@hbuckler](https://www.ruby-forum.com/u/hbuckler)\
**Post date:** [March 20, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446/3 "2010-03-20T16:39:59Z")

</div>

location / {  
root /home/path/public\_html/store; # absolute path doc  
root  
index index.php index.html index.htm;

```
            # this serves static files that exist without running 

```

other  
rewrite tests  
if (-f $request\_filename) {  
expires 30d;  
break;  
}

```
            # this sends all non-existing file or directory requests 

```

to  
index.php  
if (!-e $request\_filename) {  
rewrite ^(.+)$ /index.php last;  
}  
}

```
    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
            access_log off;
            expires 30d;
            break;
    }

    location ~ /(admin/).* {
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/htpasswd;
            fastcgi_intercept_errors On;
            fastcgi_ignore_client_abort On;
            fastcgi_buffer_size 128k;
            fastcgi_param HTTPS on;
            fastcgi_buffers 4 128k;
            root /home/path/public_html/store; # absolute path doc 

```

root  
index index.php index.html index.htm;

```
            # this serves static files that exist without running 

```

other  
rewrite tests  
if (-f $request\_filename) {  
expires 30d;  
break;  
}

```
            # this sends all non-existing file or directory requests 

```

to  
index.php  
if (!-e $request\_filename) {  
rewrite ^(.+)$ /index.php?q=$1 last;  
}  
}

```
    location ~ /(var/|report/|pkginfo/|lib/|includes/|Maged/|app/).* 

```

{  
deny all;  
}

```
    location ~ \.php$ {
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_intercept_errors On;
            fastcgi_param HTTPS on;
            fastcgi_ignore_client_abort On;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 128k;
    }

    ### EXTRA SECURITY ###
    ## Only allow GET, POST and HEAD request methods
    if ($request_method !~ ^(POST|GET|HEAD)$ ) {
            return 444;
    }

    # deny access to .htaccess files, if Apache's document root
    location ~ /\.ht {
        deny all;
    }

```

Regards,

-Team AMP  
[http://www.globalamp.com](http://www.globalamp.com)

> **[Welcome to MP3 Remix - MP3 Remix](http://www.mp3-remix.com/)**
>
> MP3 Remix is brought to you by AMP Productions. We thought we would branch off a small content site related to MP3 Remixes due the growing popularity of MP3 Remixing and MP3 Remixes. Here you will find a few articles about the essential questions...

---

<div class="post-metadata">

**Author:** ![hbuckler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/85f322/32.png) [@hbuckler](https://www.ruby-forum.com/u/hbuckler)\
**Post date:** [March 20, 2010, 4:01pm UTC](https://www.ruby-forum.com/t/help-with-nginx-config-for-magento/185446/4 "2010-03-20T16:01:52Z")

</div>

Wouter Schoot wrote:

> Hi Howard,
> 
> Untested, but I ran into this config recently:  
> [Commerce](http://www.magentocommerce.com/boards/viewthread/7931/)
> 
> Good luck.
> 
> Wouter

I have tried this Wouter but I am getting a 403 - Fordbidden Error.

Any advice on how to set permissions correctly?
