Nginx config question

Nickske00

Verified User
Joined
Nov 30, 2015
Messages
90
Hi all,

I recently got myself a new VPS with directadmin. We decided to go with nginx + apache and php-fpm. So far so good. Now I've been reading up on to nginx configuration and I need to ask something. Is it just me or does the default configuration just forward everything to apache? I thought the whole point was that static files could be loaded faster by nginx and the rest get's shipped of to apache?

This is what I see when I click on 'nginx proxy' under 'Custom HTTPD Configurations':
Code:
location /
	{
		# access_log off;
		proxy_buffering off;
		proxy_pass http://46.249.53.100:8080;
		proxy_set_header X-Client-IP      $remote_addr;
		proxy_set_header X-Accel-Internal /nginx_static_files;
		proxy_set_header Host             $host;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
	location /nginx_static_files/
	{
		# access_log  /var/log/nginx/access_log_proxy;
		alias       /home/site03/domains/buggedbrain.com/public_html/;
		internal;
	}
	include /etc/nginx/webapps.conf;

Won't something like this be better? Or am I missing something?
Code:
	location /
	{
		try_files $uri $uri/ @backend;
	}

	location @backend {
		# access_log off;
		proxy_buffering off;
		proxy_pass http://46.249.53.100:8080;
		proxy_set_header X-Client-IP      $remote_addr;
		proxy_set_header X-Accel-Internal /nginx_static_files;
		proxy_set_header Host             $host;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
	
	location ~ \.php {
		# access_log off;
		proxy_buffering off;
		proxy_pass http://46.249.53.100:8080;
		proxy_set_header X-Client-IP      $remote_addr;
		proxy_set_header X-Accel-Internal /nginx_static_files;
		proxy_set_header Host             $host;
		proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
	}
	
	include /etc/nginx/webapps.conf;

If I'm correct, when I want to use nginx now I need to call my files with 'domain.com/nginx_static_files/file.png' for example?
 
So, if i understand correct it is something like this: Request -> Nginx -> Apache (-> PHP if it is a PHP file) -> Nginx -> Client.
I this really faster than just Apache + PHP? It looks like extra work...

Sorry if I'm asking something stupid, just trying to understand. ;)
 
Okay, I think I almost understand it. From what I've read it's clear Nginx can handle more connections than Apache. So I thought the whole point of this setup was to only send the dynamic files to Apache (to keep the connections limited). But now everything gets redirected to Apache, and maybe Apache sends the static files right back to Nginx, but you still have Apache doing all the real work? Because the way I see it now it is Apache that decides to send a file to PHP or Nginx. Or am I wrong?
 
Back
Top