# Problem using Magento with nginx

**URL:** <https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657>\
**Category:** NGINX\
**Created:** [February 6, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657 "2009-02-06T19:09:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 6, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/1 "2009-02-06T19:09:02Z")

</div>

Hello -

I have installed nginx + PHP-FPM and it is working perfectly for my  
Drupal sites (nginx 0.6.33, PHP 5.2.6, FPM 0.5.9, Drupal 6.6, Debian  
Etch).

Now I am trying to use Magento (1.2.1) with nginx, and I am getting the  
error message “No input file specified.”

I have adapted the instructions for installing Magento on Debian Etch  
here:

> **[Magento E-Commerce Solution On Debian Etch](https://www.howtoforge.com/magento-e-commerce-solution-debian-etch)**
>
> Magento E-Commerce Solution On Debian Etch
> 
> This document describes how to set up Magento on Debian Etch. The
> resulting system provides a professio...

(omitting the steps involving Apache).

I have adapted the the nginx.conf files for Magento posted here:

[http://www.magentocommerce.com/boards/viewthread.../viewthread/7931/#t29161](http://www.magentocommerce.com/boards/viewthread.../viewthread/7931/#t29161)  
[http://www.ruby-forum.com/topic/130700](http://www.ruby-forum.com/topic/130700)

My nginx.conf file looks like this:

user www-data www-data;  
worker\_processes 2;

error\_log logs/error.log;  
#error\_log logs/error.log notice;  
#error\_log logs/error.log info;

pid logs/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include 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 logs/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_comp_level 1; gzip_proxied any;
gzip_types text/plain
           text/html
           text/css
           application/x-javascript
           text/xml
           application/xml
           application/xml+rss
           text/javascript;

 ## Deny access to any host other than (www.)mydomain.com
server {
     server_name _; #default
     return 444;
 }

```

# …

server {  
listen 80;  
server\_name .mysubdom.mydom.net;

```
access_log /usr/local/nginx/logs/mysubdom.access.log;
error_log /usr/local/nginx/logs/mysubdom.error.log;

gzip on;
#gzip_comp_level 9;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain application/xml text/html text/css

```

text/js application/x-javascript;

```
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
  root html;
}

# media
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|swf)$ {
  root /home/stefan/sources/magento/;
  access_log off;
  expires 30d;
  break;
}

# pass the PHP scripts to FastCGI socket
location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  fastcgi_param SCRIPT_FILENAME

```

/home/stefan/sources/magento$fastcgi\_script\_name;  
include /usr/local/nginx/conf/fastcgi\_params;  
}  
location ^~ /js/proxy.php {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_NAME $fastcgi\_script\_name;  
fastcgi\_param SCRIPT\_FILENAME  
/home/stefan/sources/magento$fastcgi\_script\_name;  
include /usr/local/nginx/conf/fastcgi\_params;  
access\_log off;  
expires 30d;  
}  
location / {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_NAME index.php;  
fastcgi\_param SCRIPT\_FILENAME  
/home/stefan/sources/magento/index.php;  
include /usr/local/nginx/conf/fastcgi\_params;  
}  
}

# …

}

My file /usr/local/nginx/conf/fastcgi\_params looks like this:

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;

fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

My Magento installation looks like this:

ls -l /home/stefan/sources/magento

total 112  
drwxrwxr-x 3 root root 4096 2009-02-02 19:11 404  
drwxrwxr-x 6 root root 4096 2009-02-02 19:11 app  
-rw-rw-r-- 1 root root 1579 2009-02-02 14:16 cron.php  
drwxrwxr-x 7 root root 4096 2009-02-02 19:11 downloader  
-rw-rw-r-- 1 root root 1150 2009-02-02 14:16 favicon.ico  
-rw-rw-r-- 1 root root 1892 2009-02-02 14:16 index.php  
-rw-rw-r-- 1 root root 1901 2009-02-02 14:16 index.php.sample  
-rw-rw-r-- 1 root root 6129 2009-02-02 14:16 install.php  
drwxrwxr-x 10 root root 4096 2009-02-02 19:11 js  
drwxrwxr-x 7 root root 4096 2009-02-02 19:11 lib  
-rw-rw-r-- 1 root root 10421 2009-02-02 14:16 LICENSE\_AFL.txt  
-rw-rw-r-- 1 root root 10410 2009-02-02 14:16 LICENSE.txt  
drwxrwxr-x 4 root www-data 4096 2009-02-02 19:11 media  
-rwxrwxr-x 1 root root 2982 2009-02-02 14:16 pear  
-rw-rw-r-- 1 root root 751 2009-02-02 14:16 php.ini.sample  
drwxrwxr-x 2 root root 4096 2009-02-02 19:11 pkginfo  
drwxrwxr-x 3 root root 4096 2009-02-02 19:11 report  
drwxrwxr-x 5 root root 4096 2009-02-02 19:11 skin  
-rw-rw-r-- 1 root root 14597 2009-02-02 14:16 STATUS.txt  
drwxrwxr-x 2 root www-data 4096 2009-02-02 19:11 var

When I point my browser at [http://mysubdom.dom.net](http://mysubdom.dom.net), I get the message:

No input file specified.

Do you have any ideas what I am doing wrong here?

Thank you for any help.

- Stefan S. Alexander

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 6, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/2 "2009-02-06T19:11:29Z")

</div>

TYPO:

> When I point my browser at [http://mysubdom.dom.net](http://mysubdom.dom.net), I get the message:

SHOULD SAY:  
When I point my browser at [http://mysubdom.MYdom.net](http://mysubdom.MYdom.net), I get the message:

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 6, 2009, 8:06pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/3 "2009-02-06T20:06:33Z")

</div>

On Fri, Feb 06, 2009 at 07:09:02PM +0100, Stefan S. wrote:

> I have adapted the instructions for installing Magento on Debian Etch  
> [Home - Magento Forums](http://www.magentocommerce.com/boards/viewthread.../viewthread/7931/#t29161)  
> #error\_log logs/error.log notice;  
> http {  
> sendfile on;  
> text/xml
> 
> # …
> 
> ```
> gzip_min_length 1000;
> }
> # pass the PHP scripts to FastCGI socket
> location ~ \.php$ {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_NAME $fastcgi_script_name;
> fastcgi_param SCRIPT_FILENAME
> 
> ```
> 
> /home/stefan/sources/magento$fastcgi\_script\_name;  
> include /usr/local/nginx/conf/fastcgi\_params;  
> }

The /js/proxy.php location probably can be handled by ~ .php$ location.

> ```
> location / {
> 
> ```
> 
> 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;
> 
> fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

You need to remove SCRIPT\_FILENAME and SCRIPT\_NAME parameters from  
/usr/local/nginx/conf/fastcgi\_params: they override the same ones  
in locations.

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 6, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/4 "2009-02-06T21:03:29Z")

</div>

I promise I’ve paid due diligence trying to solve this one through  
Google, but just can’t come up with the solution (I’ve probably  
overlooked something very simple).

In Apache, I can forward a captured variable from a RewriteCond check  
like this:  
RewriteCond %{QUERY\_STRING} tag=(._)  
RewriteRule ^fastsearch(._) /tags/%1? [L,R=301]

but I can’t seem to find the nginx equivalent as the following doesn’t  
work:  
if ($query\_string ~ "tag=(._)") {  
rewrite ^/fastsearch._ /tags/%1? permanent;  
}

My server admin is requiring that we run the stable version (0.6.35) so  
I can’t use the $arg\_PARAMETER introduced in 0.7.\*.

What am I missing?

Chris

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 7, 2009, 12:53am UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/5 "2009-02-07T00:53:12Z")

</div>

On Fri, Feb 06, 2009 at 02:53:25PM -0500, Chris Sturgill wrote:

> > but I can’t seem to find the nginx equivalent as the following doesn’t work:  
> > if ($query\_string ~ "tag=(._)") {  
> > set $tag $1;  
> > rewrite ^/fastsearch._ /tags/$tag? permanent;  
> > }

Thank you much! I had tried putting $1 directly into the rewrite  
without setting a separate variable, but got yelled at for not having a  
matching term in the left-hand side of the rewrite equation. This  
simple answer just solved several days of frustration!

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 6, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/6 "2009-02-06T21:14:38Z")

</div>

On Fri, Feb 06, 2009 at 02:53:25PM -0500, Chris Sturgill wrote:

> if ($query\_string ~ "tag=(._)") {  
> rewrite ^/fastsearch._ /tags/%1? permanent;  
> }
> 
> My server admin is requiring that we run the stable version (0.6.35) so  
> I can’t use the $arg\_PARAMETER introduced in 0.7.\*.
> 
> What am I missing?

if ($query\_string ~ "tag=(._)") {  
set $tag $1;  
rewrite ^/fastsearch._ /tags/$tag? permanent;  
}

---

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [February 7, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/problem-using-magento-with-nginx/159657/7 "2009-02-07T19:19:12Z")

</div>

Igor S. wrote:

> You need to remove SCRIPT\_FILENAME and SCRIPT\_NAME parameters from  
> /usr/local/nginx/conf/fastcgi\_params: they override the same ones  
> in locations.

Thank you so much Igor - it worked!
