handling subdirectories location

Francis Daly francis at daoine.org
Tue Jun 9 00:59:40 UTC 2015

On Mon, Jun 08, 2015 at 08:53:45PM -0300, Thiago Farina wrote:
> On Mon, Jun 8, 2015 at 8:26 PM, Francis Daly <francis at daoine.org> wrote:
> > On Mon, Jun 08, 2015 at 08:08:10PM -0300, Thiago Farina wrote:

Hi there,

> >> server {
> >>     listen       80;
> >>     server_name  domainame.com;
> >>
> >>     root /data/www/domainame.com;
> >>     include fastcgi.conf;
> >>
> >>     location ^~ /gocart/ {
> >>       location ~ \.php($|/) {
> >>         fastcgi_split_path_info (.*.php)(/.*);
> >>         fastcgi_pass; #unix:/var/run/php5-fpm.sock;
> >>       }
> >>     }
> >> }
> >>
> >> But when I navigate to http://domainame.com/gocart nginx returns 403 Forbidden.
> >
> > What response do you want?
> >
> > Be as specific as possible.
> >
> > (I suspect that the answer is "a http redirect to
> > http://domainame.com/gocart/"; but I'm reluctant to guess.)
> Isn't obvious what I want? I want the page to load, so if it is "http
> redirect to http://domainame.com/gocart/", then yes.

It's presumably obvious to you. If you are explicit, it avoids anyone
else having to guess.

What does "page to load" mean?

In this context, consider every question to be "what did you do; what
did you see; what did you expect to see?".

So: "curl -i http://domainame.com/gocart". Expect http 301 to
http://domainame.com/gocart/. Get that? Good.

"curl -i http://domainame.com/gocart/". Expect the content of the file
/data/www/domainame.com/gocart/index.html? Or the php-processed output
of the file /data/www/domainame.com/gocart/index.php? Do you get one of
those, or something else? Does a http header indicate that the php server
was involved?

Type the curl command. If the response is what you expect, report that
and be happy. If the response is not what you expect, report how it
differs. If you do not know what you expect, seek more help -- what is the
response when the thing is installed in the author-intended environment?

> > Perhaps adding "index index.html index.php;" at server-level will help?
> >
> Yes, it helps load the start page. But all the links redirects to
> http://domainame.com/gocart/.

What links are they?

Again: be explicit. Spell everything out very slowly. Maybe these links
come from something in the php that expects a specific variable to be
set to a special value; maybe they come from an application config file;
maybe you can adjust your nginx config to make everything work; maybe
you need to change something outside of nginx.

What curl command do you issue? What response do you get? What response
do you want instead?

> What I'm trying to do is not common? I thought it would be pretty
> common to do what I'm trying to do, but the solution seems to be very
> complicated for something that does not look so complicated at glance.

What does your favourite search engine return for "install [this
application] in a subdirectory on nginx"?

If it is not very much, perhaps that is because the config is so trivially
obvious that it is not worth documenting; or perhaps no-one has ever
tried it before. Which is more likely?

It looks like you are a trailblazer. This means you have to do the
legwork to be the  first person to ever get it working.

(So far, I'm seeing about a dozen lines of config, which does not strike
me as especially complicated.)

> Trying once more, what I'm trying to setup is pretty much exactly this
> https://gist.github.com/LkeMitchll/b6d8aea6c0845e3a341f,
> http://stackoverflow.com/questions/24820657/nginx-multiple-php-sites-in-sub-directories.

The first link confuses me: there's an 84-line config, and I don't see
how anything after line 42 will ever be used.

The second link doesn't show an obvious problem.

> > I don't see any obvious "how to install this on a web server, from scratch"
> > documentation on either of those web sites. Perhaps I'm looking in the
> > wrong place.
> That seems unrelated to this thread. But they all have install instructions.

If the authors will describe how they expect things to be configured
in their intended environment (web server and whatever supporting
infrastructure is required), that may help work out how things should
be configured in any other environment (such as nginx).

Good luck with it,

Francis Daly        francis at daoine.org

More information about the nginx mailing list