Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


forwarding dynamic (php) to apache vs forwarding all files to apache excluding static extensions
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

forwarding dynamic (php) to apache vs forwarding all files to apache excluding static extensions

Hi,

I've came across two ways to setup apache with nginx as reverse proxy.

# server
server {

   listen 80;

  root /path/to/site/root; 

  index index.php index.html index.htm;

  server_name www.example.com example.com;

location / {

  try_files $uri $uri/ /index.php;

 }

location ~ \.php$ {

 proxy_set_header X-Real-IP $remote_addr;

 proxy_set_header X-Forwarded-For $remote_addr;

 proxy_set_header Host $host;

 proxy_pass http://127.0.0.1:8080;

 }

}


and

# Static contents
    location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
        expires max;
    }

    # Dynamic content, forward to Apache
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;
    }

Is there any con and pro of any of these methods?

P.S. I am trying to be as clear as I can

Comments

  • TWoTWo Member

    1st method will look if the requested file exists on your server an if it doesn't will hand over to Apache.

    2nd method will serve all files with the listed extensions from Nginx and if a file with that extensions is requested but does not exists Nginx will yield a 404 for you. Everything not ending in that extension will be handed over to Apache.

  • @TWo said:
    1st method will look if the requested file exists on your server an if it doesn't will hand over to Apache.

    2nd method will serve all files with the listed extensions from Nginx and if a file with that extensions is requested but does not exists Nginx will yield a 404 for you. Everything not ending in that extension will be handed over to Apache.

    Thanks for explanations but I was looking for a view that which one will be better. Both?

  • WSSWSS Member

    Or, since nobody pays attention anyhow- use a second IP address, and put nginx on "static.dumbfuck.org", and apache on "www.dumbfuck.org". It's only worked for 20+ years..

  • TWoTWo Member

    That totally depends on your situation/setup.

    e.g. with the 2nd method if you want to serve a static file with an extension not in your list you'll need to update config.

    Personally I wouldn't use neither.

  • Well, I was opening a new thread but did stick to this one.
    I just realized that htaccess rewrite won't work for static file in this case as nginx would never send them to apache.

    Is there a workaround or what I just let it pass all requests to apache? There possibly wouldn't be any benefit of nginx but maybe cache?

  • Bump?

Sign In or Register to comment.