Is it possible using multiple directive on different root location? (Without Symlinks)

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
Hi, basic on http://wiki.nginx.org/Pitfalls, I want to ask my directives like this :

This directive on balancer :
upstream static {
        server 10.100.100.43:80; # Zenoir03
}

server {
        server_name static.antituhan.com;
        access_log  /log/nginx/static.antituhan.access.log;
        error_log  /log/nginx/static.antituhan.error.log;

        location / {
                proxy_pass http://static;
        }

}

And then, this directives on backend :
server {
        server_name localhost;
        listen 80;
        access_log  /var/log/nginx/access.log;
        error_log  /var/log/nginx/error.log debug;
        root /home/antituhan/static;

        location / {
        }

	location ~ .php$ {
                fastcgi_pass   backend-static;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include 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_intercept_errors        on;
                fastcgi_ignore_client_abort     off;
                fastcgi_connect_timeout 60;
                fastcgi_send_timeout 180;
                fastcgi_read_timeout 180;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
        }
}

upstream backend-static {
        server 127.0.0.1:9000;
}

I want to give a subdomain like this http://static.antituhan.com/cdn, and /cdn will have a root dir to /home/antituhan/public_html/, and now I use symlink to static :
$ ln -s /home/antituhan/public_html /home/antituhan/static/cdn

So, I can access the domain like this http://static.antituhan.com/cdn

If I don't use symlink, is it possible to add another directive on nginx? And if is not possible, is it safe for nginx directive? Thank you
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Cliff Wells
On Tue, 2012-05-01 at 02:36 -0700, antituhan wrote:
> Hi, basic on http://wiki.nginx.org/Pitfalls, I want to ask my directives like
> this :
>
> This directive on balancer :
>
>
> And then, this directives on backend :
>


I fear you may have over-simplified your examples.

Cliff

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
So, what should I do Cliff ? Which directive should I use for it ?
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Eliezer Croitoru
On 01/05/2012 19:58, antituhan wrote:
> So, what should I do Cliff ? Which directive should I use for it ?
how about regex match for locations?

>
> -----
> [[hidden email] ~]#
> --
> View this message in context: http://nginx.2469901.n2.nabble.com/Is-it-possible-using-multiple-directive-on-different-root-location-Without-Symlinks-tp7516384p7517418.html
> Sent from the nginx mailing list archive at Nabble.com.
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx


--
Eliezer Croitoru
https://www1.ngtech.co.il
IT consulting for Nonprofit organizations
eliezer <at> ngtech.co.il

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Francis Daly
In reply to this post by Cliff Wells
On Tue, May 01, 2012 at 09:21:13AM -0700, Cliff Wells wrote:
> On Tue, 2012-05-01 at 02:36 -0700, antituhan wrote:

Hi there,

> > this :
> >
> > This directive on balancer :
> >
> >
> > And then, this directives on backend :

I think Cliff's point is that the nabble.com interface that you are
using to post, seems to be corrupting what you post before sending it
to the nginx mailing list.

So anyone reading your message anywhere other than at nabble.com doesn't
see any of the configuration that you intended to show.

For the benefit of the list archives (and having more people who might
be able to offer help), could you repeat your first post, but do whatever
it takes to get it sent to the mailing list intact?

(That might involve some setting saying "this is plain text", perhaps.)

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Cliff Wells
In reply to this post by antituhan
Perhaps an alias?

location /cdn/ {
    alias /home/antituhan/public_html/;
}

Cliff

On Tue, 2012-05-01 at 02:36 -0700, antituhan wrote:

> Hi, basic on http://wiki.nginx.org/Pitfalls, I want to ask my directives like
> this :
>
> This directive on balancer :
>
>
> And then, this directives on backend :
>
>
> I want to give a subdomain like this http://static.antituhan.com/cdn, and
> /cdn will have a root dir to /home/antituhan/public_html/, and now I use
> symlink to static :
>
>
> So, I can access the domain like this http://static.antituhan.com/cdn
>
> If I don't use symlink, is it possible to add another directive on nginx?
> And if is not possible, is it safe for nginx directive? Thank you
>
> -----
> [[hidden email] ~]#
> --
> View this message in context: http://nginx.2469901.n2.nabble.com/Is-it-possible-using-multiple-directive-on-different-root-location-Without-Symlinks-tp7516384.html
> Sent from the nginx mailing list archive at Nabble.com.
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx



_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
This post was updated on .
If using alias, what the root document directive? Because public_html is outside the /home/antituhan/static. I've tried using alias /home/antituhan/public_html but the nginx shows errors not found. Any solution ?

Cliff Wells wrote
Perhaps an alias?

location /cdn/ {
    alias /home/antituhan/public_html/;
}

Cliff

On Tue, 2012-05-01 at 02:36 -0700, antituhan wrote:
> Hi, basic on http://wiki.nginx.org/Pitfalls, I want to ask my directives like
> this :
>
> This directive on balancer :
>
>
> And then, this directives on backend :
>
>
> I want to give a subdomain like this http://static.antituhan.com/cdn, and
> /cdn will have a root dir to /home/antituhan/public_html/, and now I use
> symlink to static :
>
>
> So, I can access the domain like this http://static.antituhan.com/cdn
>
> If I don't use symlink, is it possible to add another directive on nginx?
> And if is not possible, is it safe for nginx directive? Thank you
>
> -----
> [[hidden email] ~]#
> --
> View this message in context: http://nginx.2469901.n2.nabble.com/Is-it-possible-using-multiple-directive-on-different-root-location-Without-Symlinks-tp7516384.html
> Sent from the nginx mailing list archive at Nabble.com.
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx



_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Cliff Wells
On Tue, 2012-05-01 at 19:20 -0700, antituhan wrote:
> If using alias, what the root document directive? Becasue public_html is
> outside the /home/antituhan/static. I've tried using alias
> /home/antituhan/public_html but the nginx shows errors not found. Any
> solution ?

Pay attention to the slashes. /home/antituhan/static is not the same
as /home/antituhan/static/ for an alias.

If you could share your error log, it would be helpful.

The following works for me:

server {
    listen localhost:80;

    root /var/www/test;

    location / {
        index index.html;
    }

    location /cdn/ {
        alias /var/www/static_html/;
    }
}

index.html has <img src="/cdn/1.jpg" /> and it shows up fine.

Regards,
Cliff

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
How about php directive cliff ? I still get errors, my full directive like this http://fpaste.org/TOW3/

And i have a index.php on /home/antituhan/public_html to be triggered by another upstream outsite with http://static.antituhan.com/cdnize/index.php?q=datahere and it says not found. Is my .php directive wrong ?

Thank you

Cliff Wells wrote
On Tue, 2012-05-01 at 19:20 -0700, antituhan wrote:
> If using alias, what the root document directive? Becasue public_html is
> outside the /home/antituhan/static. I've tried using alias
> /home/antituhan/public_html but the nginx shows errors not found. Any
> solution ?

Pay attention to the slashes. /home/antituhan/static is not the same
as /home/antituhan/static/ for an alias.

If you could share your error log, it would be helpful.

The following works for me:

server {
    listen localhost:80;

    root /var/www/test;

    location / {
        index index.html;
    }

    location /cdn/ {
        alias /var/www/static_html/;
    }
}

index.html has  and it shows up fine.

Regards,
Cliff

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Francis Daly
On Thu, May 03, 2012 at 05:59:54AM -0700, antituhan wrote:

Hi there,

> How about php directive cliff ? I still get errors, my full directive like
> this http://fpaste.org/TOW3/

The important part here is that your top-level location{} directives are

location /
location /cdnize/
location ~ .php$

Each request will be handled by exactly one of those blocks.

> And i have a index.php on /home/antituhan/public_html to be triggered by
> another upstream outsite with
> http://static.antituhan.com/cdnize/index.php?q=datahere and it says not
> found. Is my .php directive wrong ?

The request for /cdnize/index.php would be handled by the "location ~
.php$" block.

In there, you have

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

and $document_root is "root", which is inherited from the

root /home/antituhan/static;

directive at server level. So this request ends up (with the fastcgi
server) looking for the file /home/antituhan/static/cdnize/index.php,
which is presumably not what you want.

Probably you'll want to look at nesting a php location inside the /cdnize/
one. And then moving the current php location to be inside the / one.

So you will probably need to have two or more locations that handle php,
which each use a fastcgi_pass directive.

I'm sure there are recent examples of this set-up on the mailing list.

Good luck with it,

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
So, how to solve the fastcgi php path with $document_root directive? By using fix path like /home/antituhan/static + multiple fastcgi directive or any directive to solve this issue?

Francis Daly wrote
On Thu, May 03, 2012 at 05:59:54AM -0700, antituhan wrote:

Hi there,

> How about php directive cliff ? I still get errors, my full directive like
> this http://fpaste.org/TOW3/

The important part here is that your top-level location{} directives are

location /
location /cdnize/
location ~ .php$

Each request will be handled by exactly one of those blocks.

> And i have a index.php on /home/antituhan/public_html to be triggered by
> another upstream outsite with
> http://static.antituhan.com/cdnize/index.php?q=datahere and it says not
> found. Is my .php directive wrong ?

The request for /cdnize/index.php would be handled by the "location ~
.php$" block.

In there, you have

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

and $document_root is "root", which is inherited from the

root /home/antituhan/static;

directive at server level. So this request ends up (with the fastcgi
server) looking for the file /home/antituhan/static/cdnize/index.php,
which is presumably not what you want.

Probably you'll want to look at nesting a php location inside the /cdnize/
one. And then moving the current php location to be inside the / one.

So you will probably need to have two or more locations that handle php,
which each use a fastcgi_pass directive.

I'm sure there are recent examples of this set-up on the mailing list.

Good luck with it,

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Francis Daly
On Thu, May 10, 2012 at 09:58:10PM -0700, antituhan wrote:

Hi there,

> So, how to solve the fastcgi php path with $document_root directive? By using
> fix path like /home/antituhan/static + multiple fastcgi directive or any
> directive to solve this issue?

If this part:

> > Probably you'll want to look at nesting a php location inside the /cdnize/
> > one. And then moving the current php location to be inside the / one.
> >
> > So you will probably need to have two or more locations that handle php,
> > which each use a fastcgi_pass directive.

is unclear, please say so.

After that:

* what did you do?
* what did you see?
* what did you expect to see?

(As in: show your config; and show one url that you tested that did not
respond as you wanted.)

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
Hello f,

Sorry for longtime no reply to this thread, because of another project. I want to continue this case, and I try the directive like this http://fpaste.org/n8FS/

I got the reference from here http://serverfault.com/questions/415538/nginx-alias-and-regex

Change $document_root$fastcgi_script_name into $document_root$1, but I still got 403 Forbidden when access http://static.antituhan.com/test/tehbotol.php
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Francis Daly
On Tue, Nov 27, 2012 at 04:08:21AM -0800, antituhan wrote:

Hi there,

> Change $document_root$fastcgi_script_name into $document_root$1, but I still
> got 403 Forbidden when access http://static.antituhan.com/test/tehbotol.php

What file do you want the fastcgi server to process when you request
http://static.antituhan.com/test/tehbotol.php?

If it is /something/test/tehboto1.php, then put "root /something" inside
the location{} block and use $document_root$fastcgi_script_name.

If it isn't, then you'll need to build what it is in some other way.

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
Hi F,

Yup, i want the fastcgi server to process the .php files. I've tried to set like this

location /test/ {
    root /something/;
}

While I access http://static.antituhan.com/test/tehbotol.php the error log shows that tehbotol.php can't found on /something/test/tehbotol.php

Francis Daly wrote
On Tue, Nov 27, 2012 at 04:08:21AM -0800, antituhan wrote:

Hi there,

> Change $document_root$fastcgi_script_name into $document_root$1, but I still
> got 403 Forbidden when access http://static.antituhan.com/test/tehbotol.php

What file do you want the fastcgi server to process when you request
http://static.antituhan.com/test/tehbotol.php?

If it is /something/test/tehboto1.php, then put "root /something" inside
the location{} block and use $document_root$fastcgi_script_name.

If it isn't, then you'll need to build what it is in some other way.

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
[daemon@antituhan.com ~]#
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

Francis Daly
On Tue, Dec 04, 2012 at 08:10:37AM -0800, antituhan wrote:

> While I access http://static.antituhan.com/test/tehbotol.php the error log
> shows that tehbotol.php can't found on /something/test/tehbotol.php

What file do you want the fastcgi server to process when you request
http://static.antituhan.com/test/tehbotol.php?

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible using multiple directive on different root location? (Without Symlinks)

antituhan
tehbotol.php content is :

<?php phpinfo(); ?>

Francis Daly wrote
On Tue, Dec 04, 2012 at 08:10:37AM -0800, antituhan wrote:

> While I access http://static.antituhan.com/test/tehbotol.php the error log
> shows that tehbotol.php can't found on /something/test/tehbotol.php

What file do you want the fastcgi server to process when you request
http://static.antituhan.com/test/tehbotol.php?

        f
--
Francis Daly        [hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
[daemon@antituhan.com ~]#