Welcome! Log In Create A New Profile

Advanced

Re: Newbie questions about nginx (moving from apache)

Maxim Dounin
May 28, 2011 10:34AM
Hello!

On Sat, May 28, 2011 at 09:55:10AM -0400, pk899 wrote:

> Thanks. But I am a bit confused, as the simple setup is not working from
> port 81 (for testing):
>
>
> server {
> listen 81;
> server_name MYDOMAIN.com www.MYDOMAIN.com;
>
> location ^~ /site/static {
> root /home/MYDOMAIN/www/static;
> index index.htm index.php;
> expires 30d;
> gzip on;
> }
>
> location / {
> proxy_pass http://127.0.0.1:80/;
> proxy_redirect off;
>
> proxy_set_header Host $host;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> }
>
> }
>
>
>
> Then I try in my browser this:
> http://MYDOMAIN.com:81/test.gif
>
> On the server the "test.gif" file is at
> "/home/MYDOMAIN/www/static/test.gif".
>
> Questions:
>
> (1) What am I missing? Should the test.gif file be somewhere else?
> Should I try this with some other URL instead of the one I mention
> above?

It looks like you don't understand at least two basic things:

1. Location directive maps *URI* namespace to configuration.
That is, with your config /test.gif will be mapped to "location
/", i.e. will be proxy_pass'ed to Apache. You want to request
something like /site/static/test.gif to be actually served by
nginx itself.

See here for more details:

http://wiki.nginx.org/HttpCoreModule#location

2. Root directive define *root*, and URI will be added to it to
map request to filesystem. I.e. with URI /site/static/test.gif
and root /home/MYDOMAIN/www/static you will end up with
"/home/MYDOMAIN/www/static/site/static/test.gif" filename.

If you want "/site/static/test.gif" to be mapped to
"/home/MYDOMAIN/www/static/test.gif" you have to use alias
directive instead.

See here for more details:

http://wiki.nginx.org/HttpCoreModule#root
http://wiki.nginx.org/HttpCoreModule#alias

> (2) Also, if this worked, and I accepted Nginx to be at the front and
> moved Apache to the background, isn't it true that Apache would have to
> pass back all processed output to Nginx?

Yes. And this is a huge win in many cases: Apache processes won't
be bound by serving responses to slow clients.

> (3) Even with "proxy_redirect off", when I try http://MYDOMAIN.com:81,
> it actually does a hard 301 redirect to my Apache server.

Directive proxy_redirect is to fix redirects returned by backend
server. By switching it off you merely said "don't touch
anything" to nginx, and this is what it does. I.e. redirect is
returned by your Apache server (alternatively, it may be just your
browser's cache from previous testing - check logs).

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Newbie questions about nginx (moving from apache)

pk899 May 27, 2011 04:14AM

Re: Newbie questions about nginx (moving from apache)

Igor Sysoev May 27, 2011 04:26AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 27, 2011 04:28AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 27, 2011 12:19PM

Re: Newbie questions about nginx (moving from apache)

Igor Sysoev May 27, 2011 04:36AM

Re: Newbie questions about nginx (moving from apache)

Igor Sysoev May 27, 2011 12:44PM

Re: Newbie questions about nginx (moving from apache)

pk899 May 27, 2011 12:59PM

Re: Newbie questions about nginx (moving from apache)

pk899 May 27, 2011 11:54PM

Re: Newbie questions about nginx (moving from apache)

Thomas Love May 28, 2011 09:24AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 28, 2011 09:31AM

Re: Newbie questions about nginx (moving from apache)

Thomas Love May 28, 2011 09:58AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 28, 2011 10:28AM

Re: Newbie questions about nginx (moving from apache)

Thomas Love May 28, 2011 09:32AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 28, 2011 09:55AM

Re: Newbie questions about nginx (moving from apache)

Thomas Love May 28, 2011 10:06AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 28, 2011 10:18AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 28, 2011 10:20AM

Re: Newbie questions about nginx (moving from apache)

Maxim Dounin May 28, 2011 10:34AM

Re: Newbie questions about nginx (moving from apache)

pk899 May 29, 2011 01:11AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready