Discussion:
Nginx "alias" setup
r***@webworxshop.com
2011-09-17 23:14:04 UTC
Permalink
Hi All,

I'm trying to migrate all the web apps on my server from Apache to
Nginx. So far I'm quite liking it's clean configuration style and it
seems (subjectively) quicker. However, I'm having problems reproducing a
particular part of my Apache configuration, here is my situation:

I have a virtual host, which I use for my webmail. The document root
points to Roundcube, located at /usr/share/roundcubemail. On the same
host I also want to run postfixadmin, located at /var/www/postfixadmin.
In Apache this would be as simple as:

Alias /postfixadmin /var/www/postfixadmin

Followed by a location block to define permissions, etc.

In Nginx the closest I've been able to get is:

location /postfixadmin {
root /var/www;
try_files $uri $uri/ /postfixadmin/index.php;
}

location ~ ^/postfixadmin/(.+\.php)$ {
root /var/www;
try_files $uri =404;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}

Which when I visit the URL redirects me to the login page, however none
of the static resources load. Looking at the logs it looks like anything
which is not a PHP script is giving a 404 error. My understanding is
that the first location block should be catching these, but obviously it
isn't.

Can anyone tell me what I'm missing? Also, is there a better way to go
about what I'm trying to do?

Thanks in advance,

Rob


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
Steve Holdoway
2011-09-21 23:50:12 UTC
Permalink
Post by r***@webworxshop.com
Hi All,
I'm trying to migrate all the web apps on my server from Apache to
Nginx. So far I'm quite liking it's clean configuration style and it
seems (subjectively) quicker. However, I'm having problems reproducing a
I have a virtual host, which I use for my webmail. The document root
points to Roundcube, located at /usr/share/roundcubemail. On the same
host I also want to run postfixadmin, located at /var/www/postfixadmin.
Alias /postfixadmin /var/www/postfixadmin
Followed by a location block to define permissions, etc.
location /postfixadmin {
root /var/www;
try_files $uri $uri/ /postfixadmin/index.php;
}
location ~ ^/postfixadmin/(.+\.php)$ {
root /var/www;
try_files $uri =404;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
Which when I visit the URL redirects me to the login page, however none
of the static resources load. Looking at the logs it looks like anything
which is not a PHP script is giving a 404 error. My understanding is
that the first location block should be catching these, but obviously it
isn't.
Can anyone tell me what I'm missing? Also, is there a better way to go
about what I'm trying to do?
Thanks in advance,
Rob
Hmmm... yes they should be. It's not a permissions problem is it?

Steve
--
Steve Holdoway BSc(Hons) MNZCS <***@greengecko.co.nz>
http://www.greengecko.co.nz
MSN: ***@greengecko.co.nz
Skype: sholdowa
r***@webworxshop.com
2011-09-24 23:54:58 UTC
Permalink
Post by Steve Holdoway
Hmmm... yes they should be. It's not a permissions problem is it?
Steve
I don't think so, php is running as 'www-data' and nginx as 'nginx',
but the files are world readable:

$ ls -la /var/www/postfixadmin/
total 472
drwxr-xr-x 14 root www-data 4096 Sep 17 17:56 .
drwxr-xr-x 11 root root 4096 Sep 18 12:00 ..
drwxr-xr-x 4 root www-data 4096 Sep 17 17:56 ADDITIONS
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 admin
-rw-r--r-- 1 root www-data 4021 Sep 17 17:56 backup.php
-rw-r--r-- 1 root www-data 3086 Sep 17 17:56 broadcast-message.php
-rw-r--r-- 1 root www-data 24161 Sep 17 17:56 CHANGELOG.TXT
-rw-r--r-- 1 root www-data 1947 Sep 17 17:56 common.php
-rw-r--r-- 1 root www-data 17349 Sep 17 17:56 config.inc.php
-rw-r--r-- 1 root www-data 1913 Sep 17 17:56 create-admin.php
-rw-r--r-- 1 root www-data 4360 Sep 17 17:56 create-alias-domain.php
-rw-r--r-- 1 root www-data 6049 Sep 17 17:56 create-alias.php
-rw-r--r-- 1 root www-data 4924 Sep 17 17:56 create-domain.php
-rw-r--r-- 1 root www-data 9060 Sep 17 17:56 create-mailbox.php
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 css
drwxr-xr-x 4 root www-data 4096 Sep 17 17:56 debian
-rw-r--r-- 1 root www-data 6194 Sep 17 17:56 delete.php
drwxr-xr-x 3 root www-data 4096 Sep 17 17:56 DOCUMENTS
-rw-r--r-- 1 root www-data 1460 Sep 17 17:56 edit-active-admin.php
-rw-r--r-- 1 root www-data 1421 Sep 17 17:56 edit-active-domain.php
-rw-r--r-- 1 root www-data 3513 Sep 17 17:56 edit-active.php
-rw-r--r-- 1 root www-data 4851 Sep 17 17:56 edit-admin.php
-rw-r--r-- 1 root www-data 5819 Sep 17 17:56 edit-alias.php
-rw-r--r-- 1 root www-data 3552 Sep 17 17:56 edit-domain.php
-rw-r--r-- 1 root www-data 5246 Sep 17 17:56 edit-mailbox.php
-rw-r--r-- 1 root www-data 6895 Sep 17 17:56 edit-vacation.php
-rw-r--r-- 1 root www-data 9106 Sep 17 17:56 fetchmail.php
-rw-r--r-- 1 root www-data 69801 Sep 17 17:56 functions.inc.php
-rw-r--r-- 1 root www-data 15148 Sep 17 17:56 GPL-LICENSE.TXT
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 images
-rw-r--r-- 1 root www-data 3599 Sep 17 17:56 index.php
-rw-r--r-- 1 root www-data 4972 Sep 17 17:56 INSTALL.TXT
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 languages
-rw-r--r-- 1 root www-data 1569 Sep 17 17:56 LICENSE.TXT
-rw-r--r-- 1 root www-data 1079 Sep 17 17:56 list-admin.php
-rw-r--r-- 1 root www-data 3649 Sep 17 17:56 list-domain.php
-rw-r--r-- 1 root www-data 10796 Sep 17 17:56 list-virtual.php
-rw-r--r-- 1 root www-data 3097 Sep 17 17:56 login.php
-rw-r--r-- 1 root www-data 722 Sep 17 17:56 logout.php
-rw-r--r-- 1 root www-data 875 Sep 17 17:56 main.php
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 model
-rw-r--r-- 1 root www-data 264 Sep 17 17:56 motd.txt
-rw-r--r-- 1 root www-data 264 Sep 17 17:56 motd-users.txt
-rw-r--r-- 1 root www-data 2776 Sep 17 17:56 password.php
-rw-r--r-- 1 root www-data 4205 Sep 17 17:56 search.php
-rw-r--r-- 1 root www-data 2156 Sep 17 17:56 sendmail.php
-rw-r--r-- 1 root www-data 14785 Sep 17 17:56 setup.php
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 templates
drwxr-xr-x 3 root www-data 4096 Sep 17 17:56 tests
-rw-r--r-- 1 root www-data 52389 Sep 17 17:56 upgrade.php
drwxr-xr-x 2 root www-data 4096 Sep 17 17:56 users
-rw-r--r-- 1 root www-data 2306 Sep 17 17:56 variables.inc.php
-rw-r--r-- 1 root www-data 2282 Sep 17 17:56 viewlog.php
drwxr-xr-x 3 root www-data 4096 Sep 17 17:56 VIRTUAL_VACATION
-rw-r--r-- 1 root www-data 4878 Sep 17 17:56 xmlrpc.php

Also removing the second location block (that serves the php) and then
browsing to an image file worked so the webserver can definitely find
the files.

Cheers,

Rob


_______________________________________________
NZLUG mailing list ***@linux.net.nz
http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug

Loading...