Reverse-proxy NGINX + Apache on Directadmin powered server with CB 2.x

Please post the output of:
Code:
ls -l / | grep home
ls -l /home | grep znak

And:
Code:
ls -l /home/znak/domains/userdomain.com/public_html/administrator/templates/khepri/js/menu.js

It might be that /home or /home/user is set to chmod 710, while it should be set to at least 711 (unless directories are owner by user:access).
 
Is any possibility to turn off reverse proxy for selected domains?
That would be great, as well as being able to use NGINX exclusively for some sites which we know don't need .htaccess per example or for customers who speak NGINX only.
 
Code:
root@server:/# ls -l / | grep home
drwx--x--x  37 root root   4096 wrz 13 01:10 home

root@server:/# ls -l /home | grep znak
drwx--x---  8 znak          access   4096 sty  3  2014 znak

root@server:/# ls -l /home/znak/domains/znak-osk.pl/public_html/administrator/templates/khepri/js/menu.js
-rw-r--r-- 1 znak znak 1569 mar  8  2012 /home/znak/domains/znak-osk.pl/public_html/administrator/templates/khepri/js/menu.js
root@server:/#

Have you any idea why after few nginx restart more domains have the same problem. After re-build nginx_apche problem affect only one user (znak) but before that 4 domains have the same problem (all with joomla).

Regards
 
Last edited:
Please give the following a try:
Code:
usermod -G access nginx

If it still doesn't work after that, do the following for znak user and see if znak-osk.pl works then:
Code:
chmod 711 /home/znak
 
Dosen't work :/
Nginx was restarted after changes.

Problem affect only one user. I have no idea why.
User have not custom settings (httpd.conf, nginx.conf, php.ini). When clean apache is running site work's fine.

Regards
 
Last edited:
I was wondering, is this cb setting a full nginx apache proxy, or is nginx serving static files directly by itself? Is it caching results form apache? And is anyone using this and is seeing increased performance? Thanks :)
 
Nginx serves static content, and sits in front of apache :) But it's still a full nginx, setup as a reverse proxy, setup. I'm not sure what did you want to say using the word "full".
 
Dosen't work :/
Nginx was restarted after changes.

Problem affect only one user. I have no idea why.
User have not custom settings (httpd.conf, nginx.conf, php.ini). When clean apache is running site work's fine.

Regards

May I check it directly on your server? (free of charge)
 
I have no idea why, but JohnyByk had all directories in public_html set to chmod 711. As nginx needs to have "read" permission for files, I changed the folders to 755, and it solved the problem.

Code:
find /home/*/domains/*/public_html -type d -print -exec chmod 0755 {} \;
 
I don't know too. It was long ago ... in a galaxy far far away :].

Thanks for help.
Nginx as proxy works much faste for static content.

Regards
 
Nginx serves static content, and sits in front of apache :) But it's still a full nginx, setup as a reverse proxy, setup. I'm not sure what did you want to say using the word "full".

What I mean is that is nginx accessing the static files by itself, or is it letting apache accessing the files and then pass that through to the client. As I just read that nginx needs read access, I assume it is accessing it by itself.

But then I wonder, is there a config where it is decided which files are static? If I had a mod rewrite e.g. /avatars/12.jpg to avatar.php?img=$1 -- would nginx think it's a static file, or would it proceed to apache/htaccess -> php?
 
Yes, nginx should have access to static files.

About your question: "avatars/12.jpg" is a static file, so it will be served by nginx :)

Arieh said:
would it proceed to apache/htaccess

.htaccess and serving static files are 2 completely different things :) So your question is incorrect. Please explain if that's not what you wanted to ask: when nginx gets a request (for example "avatar.php?img=$1"), htaccess file is processed, then it's known that the file is a static one, so it instantly requests nginx to serve the static file.
 
Yes, nginx should have access to static files.

About your question: "avatars/12.jpg" is a static file, so it will be served by nginx :)



.htaccess and serving static files are 2 completely different things :) So your question is incorrect. Please explain if that's not what you wanted to ask: when nginx gets a request (for example "avatar.php?img=$1"), htaccess file is processed, then it's known that the file is a static one, so it instantly requests nginx to serve the static file.

No I mean if a rewrite rule makes it look like it's a static file, while it actually isn't. I mean with the example that /avatar/12.jpg looks like a static file for the visitor, but actually is a rewrite to avatar.php?img=$1 -- where $1 would be 12, and would be used in a query to get the actual image name from mysql with the id 12. (Don't mind the usefulness in this example).

So I wondered, is it just checking the extension of the request, then it decides to try to read it from the disk, or pass the url through to apache?
 
That would be processed by apache then (if you have a rewrite rule for /avatar/12.jpg), but the image itself would still be served by nginx, after the PHP file gets processed.
 
So, I'm guessing there will be no speed improvement in this case, since the PHP will have to be processed every time and worse, several .htaccess files have to be loaded every time as well.
 
There's still performance improvement with it. Reasons for that:
1) Nginx sits in front of apache, it's nginx accepting all of the connections and dealing with them (in any cases, including DDoS).
2) Static content is sent by nginx, not apache, apache is just requesting nginx to send particular files.
3) With proxy_buffering enabled (http://www.directadmin.com/features.php?id=1643), nginx stores data in a buffer. Meaning first byte isn't sent till Apache finishes processing. That's very useful for slow connections, as connection time is takes less time, because nginx asks apache to serve the request on a localhost level, then apache sends a complete response to nginx, which is sent to the client immediately.
4) Caching for static content could be setup in nginx, providing more efficiency.

It's easy to change the way how requests are processed (that could be done in templates), however, I wouldn't recommend serving static content without processing of .htaccess files, because that would mean your nginx+apache combination is not a drop-in replacement for apache, and things like password protection for images, hotlink protection, rewrites for static content to be served by dynamic (PHP) files wouldn't work anymore :)
 
I said in this particular case, where .htaccess has to be processed at every request, unless NGINX trusts that /avatar.php?img=12 is always /avatar/12.jpg and serves the request immediately, bypassing Apache, but I don't think that's what the rules say.
 
Yes, you're right about the mentioned case with img rewrite :) But that applies for a standalone apache too, because it would serve the image faster without processing the PHP file for every image call.
 
The reason I asked is because I've got files which require authentication by login session, in combination with a framework which accepts parameters by rewrite.

But then I'm just curious, how does nginx process the htaccess?
 
Back
Top