<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Location - or how to setup sites in subfolders</title>
<description>I'm trying to give nginx a try as an alternative to my current server 
solutions. Named-based virtual hosting SEEMS straightforward enough - 
but I'm having a devil of a time trying to get subfolder based sites to 
work. In other words -
egroupware.mydomain.com
roundcubemail.mydomain.com
ldap-account-manager.mydomain.com
for some examples, work just fine. But trying to get -
www.mydomain.com/egroupware
www.mydomain.com/roundcubemail
www.mydomain.com/ldap-account-manager
to work is an exercise in extreme frustration. I'm sure it doesn't HAVE 
to be - but Google thus far has let me down in retrieving the 
information I need. What I've done thus far, for egroupware for example:
I have a site file with:
server {
server_name www.amfeslan.local egroupware.amfeslan.local;
root /opt/egroupware;
index index.php;
client_max_body_size 8M;
rewrite ^/egroupware/(.*)$ /$1 last;
try_files $uri $uri/ /index.php$args;
include global/php.conf;
}
my global/php.conf has:
location ~ \.php$ {
# There's gotta be a better way to do this - try and find it.
# Since nginx's &amp;quot;best&amp;quot; match is this one - need to do rewrites
# here to get subfolders to work.
set $php_root $document_root;
if ($request_uri ~* /egroupware) {
set $php_root /opt/egroupware;
}
# Zero-day exploit defense.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
fastcgi_pass php;
}
Note that I tried to add the &amp;quot;if&amp;quot; construct in php.conf based on a 
previous post - and I gotta believe there's a better way to do this. 
With or without the if construct, the above site works - but only for 
egroupware. Revising the site file to:
server {
server_name www.amfeslan.local egroupware.amfeslan.local;
root /var/www;
index index.html;
client_max_body_size 8M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ^~ /egroupware {
root /opt/egroupware;
index index.php;
rewrite ^/egroupware/(.*)$ /$1 last;
try_files $uri $uri/ /index.php$args;
}
include global/php.conf;
}
Doesn't work right. Can some kind soul help me not only fix this - but 
get a better understanding of how to build these generic constructs? 
Based on experience with other servers, I can't believe folder-based 
controls in nginx can be as difficult as I seem to be making it!
-- 
Daniel
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx</description><link>http://forum.nginx.org/read.php?2,225909,225909#msg-225909</link><lastBuildDate>Tue, 21 May 2013 03:00:16 -0400</lastBuildDate>
<generator>Phorum 5.2.16</generator>
<item>
<guid>http://forum.nginx.org/read.php?2,225909,225911#msg-225911</guid>
<title>Re: Location - or how to setup sites in subfolders</title><link>http://forum.nginx.org/read.php?2,225909,225911#msg-225911</link><description><![CDATA[On 4/29/2012 1:22 PM, Edho Arief wrote:<br />&gt; 2012/4/30 Daniel L. Miller&lt;dmiller@amfes.com&gt;:<br />&gt;&gt; Note that I tried to add the &quot;if&quot; construct in php.conf based on a previous<br />&gt;&gt; post - and I gotta believe there's a better way to do this. With or without<br />&gt;&gt; the if construct, the above site works - but only for egroupware.<br />[..]<br />&gt;&gt; Doesn't work right. Can some kind soul help me not only fix this - but get<br />&gt;&gt; a better understanding of how to build these generic constructs? Based on<br />&gt;&gt; experience with other servers, I can't believe folder-based controls in<br />&gt;&gt; nginx can be as difficult as I seem to be making it!<br />&gt; Put &quot;location ~ \.php$ { }&quot; inside each &quot;location ^~ /appname/ { }&quot;<br />&gt; block instead of globally so it looks like this:<br />&gt;<br />&gt; location ^~ /egroupware/ {<br />&gt; # if index.php's path is /opt/egroupware/index.php,<br />&gt; # use &quot;root /opt&quot; instead<br />&gt; root /opt/egroupware;<br />&gt; index index.php;<br />&gt; # and remove this<br />&gt; rewrite ^/egroupware/(.*)$ /$1 last;<br />&gt; # and update this accordingly<br />&gt; try_files $uri $uri/ /index.php$args;<br />&gt; location ~ \.php($|/) {<br />&gt; ...<br />&gt; }<br />&gt; }<br />&gt;<br /><br />Thank you! - that helped quite a bit. That way of thinking - of<br />including the php handler inside each location, instead of a global php<br />handler, just didn't seem as &quot;elegant&quot; to me - but I can see the power<br />potential.<br /><br />However - I still don't understand WHY it works - specifically, why I<br />need to have &quot;root /opt&quot; instead of &quot;root /opt/egroupware&quot;. I'm<br />inferring that the location path is automatically added to the declared<br />root in processing. But if that's the case, then to be able to declare,<br />&quot;location ^~ /lam/&quot;, and be able to reach a physical path of<br />&quot;/opt/ldap-account-manager-3.7&quot;, I need to add a symlink from the<br />extended path to &quot;/opt/lam&quot;. And while I may in fact do so for other<br />reasons - I WOULD like to be able to control exactly what nginx is<br />doing, and better yet - understand the how/why.<br />--<br />Daniel<br /><br />_______________________________________________<br />nginx mailing list<br />nginx@nginx.org<br />http://mailman.nginx.org/mailman/listinfo/nginx]]></description>
<dc:creator>Daniel L. Miller</dc:creator>
<category>Nginx Mailing List - English</category><pubDate>Sun, 29 Apr 2012 17:18:00 -0400</pubDate></item>
<item>
<guid>http://forum.nginx.org/read.php?2,225909,225910#msg-225910</guid>
<title>Re: Location - or how to setup sites in subfolders</title><link>http://forum.nginx.org/read.php?2,225909,225910#msg-225910</link><description><![CDATA[2012/4/30 Daniel L. Miller &lt;dmiller@amfes.com&gt;:<br />&gt; Note that I tried to add the &quot;if&quot; construct in php.conf based on a previous<br />&gt; post - and I gotta believe there's a better way to do this.  With or without<br />&gt; the if construct, the above site works - but only for egroupware.  Revising<br />&gt; the site file to:<br />&gt; server {<br />&gt;    server_name www.amfeslan.local egroupware.amfeslan.local;<br />&gt;    root /var/www;<br />&gt;    index index.html;<br />&gt;<br />&gt;    client_max_body_size 8M;<br />&gt;<br />&gt;    location / {<br />&gt;       try_files $uri $uri/ /index.php?$args;<br />&gt;    }<br />&gt;<br />&gt;    location ^~ /egroupware {<br />&gt;       root /opt/egroupware;<br />&gt;       index index.php;<br />&gt;       rewrite ^/egroupware/(.*)$ /$1 last;<br />&gt;       try_files $uri $uri/ /index.php$args;<br />&gt;    }<br />&gt;<br />&gt;    include global/php.conf;<br />&gt; }<br />&gt;<br />&gt; Doesn't work right.  Can some kind soul help me not only fix this - but get<br />&gt; a better understanding of how to build these generic constructs?  Based on<br />&gt; experience with other servers, I can't believe folder-based controls in<br />&gt; nginx can be as difficult as I seem to be making it!<br /><br />Put &quot;location ~ \.php$ { }&quot; inside each &quot;location ^~ /appname/ { }&quot;<br />block instead of globally so it looks like this:<br /><br />location ^~ /egroupware/ {<br /># if index.php's path is /opt/egroupware/index.php,<br /># use &quot;root /opt&quot; instead<br />root /opt/egroupware;<br />index index.php;<br /># and remove this<br />rewrite ^/egroupware/(.*)$ /$1 last;<br /># and update this accordingly<br />try_files $uri $uri/ /index.php$args;<br />location ~ \.php($|/) {<br />...<br />}<br />}<br /><br />Also remember that some applications may need to know that it's<br />running in a subdirectory or it will generate incorrect link (eg.<br />/something.php instead of /app/something.php).<br /><br />_______________________________________________<br />nginx mailing list<br />nginx@nginx.org<br />http://mailman.nginx.org/mailman/listinfo/nginx]]></description>
<dc:creator>Edho Arief</dc:creator>
<category>Nginx Mailing List - English</category><pubDate>Sun, 29 Apr 2012 16:24:00 -0400</pubDate></item>
<item>
<guid>http://forum.nginx.org/read.php?2,225909,225909#msg-225909</guid>
<title>Location - or how to setup sites in subfolders</title><link>http://forum.nginx.org/read.php?2,225909,225909#msg-225909</link><description><![CDATA[I'm trying to give nginx a try as an alternative to my current server<br />solutions. Named-based virtual hosting SEEMS straightforward enough -<br />but I'm having a devil of a time trying to get subfolder based sites to<br />work. In other words -<br /><br />egroupware.mydomain.com<br />roundcubemail.mydomain.com<br />ldap-account-manager.mydomain.com<br /><br />for some examples, work just fine. But trying to get -<br /><br />www.mydomain.com/egroupware<br />www.mydomain.com/roundcubemail<br />www.mydomain.com/ldap-account-manager<br /><br />to work is an exercise in extreme frustration. I'm sure it doesn't HAVE<br />to be - but Google thus far has let me down in retrieving the<br />information I need. What I've done thus far, for egroupware for example:<br /><br />I have a site file with:<br />server {<br />server_name www.amfeslan.local egroupware.amfeslan.local;<br />root /opt/egroupware;<br />index index.php;<br /><br />client_max_body_size 8M;<br />rewrite ^/egroupware/(.*)$ /$1 last;<br />try_files $uri $uri/ /index.php$args;<br /><br />include global/php.conf;<br />}<br /><br />my global/php.conf has:<br />location ~ \.php$ {<br /># There's gotta be a better way to do this - try and find it.<br /># Since nginx's &quot;best&quot; match is this one - need to do rewrites<br /># here to get subfolders to work.<br />set $php_root $document_root;<br />if ($request_uri ~* /egroupware) {<br />set $php_root /opt/egroupware;<br />}<br /><br /># Zero-day exploit defense.<br />try_files $uri =404;<br /><br />fastcgi_split_path_info ^(.+\.php)(/.+)$;<br /><br />include fastcgi_params;<br />fastcgi_index index.php;<br />fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;<br />fastcgi_pass php;<br />}<br /><br />Note that I tried to add the &quot;if&quot; construct in php.conf based on a<br />previous post - and I gotta believe there's a better way to do this.<br />With or without the if construct, the above site works - but only for<br />egroupware. Revising the site file to:<br />server {<br />server_name www.amfeslan.local egroupware.amfeslan.local;<br />root /var/www;<br />index index.html;<br /><br />client_max_body_size 8M;<br /><br />location / {<br />try_files $uri $uri/ /index.php?$args;<br />}<br /><br />location ^~ /egroupware {<br />root /opt/egroupware;<br />index index.php;<br />rewrite ^/egroupware/(.*)$ /$1 last;<br />try_files $uri $uri/ /index.php$args;<br />}<br /><br />include global/php.conf;<br />}<br /><br />Doesn't work right. Can some kind soul help me not only fix this - but<br />get a better understanding of how to build these generic constructs?<br />Based on experience with other servers, I can't believe folder-based<br />controls in nginx can be as difficult as I seem to be making it!<br />--<br />Daniel<br /><br />_______________________________________________<br />nginx mailing list<br />nginx@nginx.org<br />http://mailman.nginx.org/mailman/listinfo/nginx]]></description>
<dc:creator>Daniel L. Miller</dc:creator>
<category>Nginx Mailing List - English</category><pubDate>Sun, 29 Apr 2012 16:08:00 -0400</pubDate></item>
</channel>
</rss>