The sites-* folders are managed by nginx_ensite
and nginx_dissite
. For Apache httpd users who find this with a search, the equivalents is a2ensite
/a2dissite
.
The sites-available
folder is for storing all of your vhost configurations, whether or not they're currently enabled.
The sites-enabled
folder contains symlinks to files in the sites-available folder. This allows you to selectively disable vhosts by removing the symlink.
conf.d
does the job, but you have to move something out of the folder, delete it, or make changes to it when you need to disable something. The sites-* folder abstraction makes things a little more organized and allows you to manage them with separate support scripts.
(unless you're like me, and one of many debian admins who just managed the symlinks directly, not knowing about the scripts...)
Okay, you want to run multiple PHP version through nginx, the configure file should
includes the specific path where you put your PHP scripts in different version or extension name.
However, I would like to explain the SF question link given in your post.
That answer is giving you a way to modify the conf
of your nginx
, which assumes that questioner has background in nginx
.
By giving a specific port in conf
, nginx will make the script executed through that FastCGI channel.
Let's pretend you have installed different PHP version in your server, and you have modified the port
in php-fpm.conf
.
You wish all php
file executed in version 5.5.0
and php2
file executed in 5.6.0
.
Example config of nginx as follows,
listen 8080;
server_name localhost;
root html;
location / {
index index.php index.php2;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME "${document_root}${fastcgi_script_name}";
include fastcgi_params;
}
location ~ \.php2$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME "${document_root}${fastcgi_script_name}";
include fastcgi_params;
}
In this case, php
is processed through port 9000
and php2
goes to 9001
This is jsut a simple example, for advanced you can make two different folders to store php files, for example, /home/php55
and /home/php56
, then edit your nginx.conf
.
FOR YOUR EDITED QUESTION
If you want to try adding different servers to process the scripts in different version, sure you can do that, because nginx can be a load balancer, it can deal with this kind of problem as well.
First Application
server{
listen 80;
server_name php1.localhost;
root /home/www/php5.5;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9002; (You can change it to your private IP in the future)
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Second Application
server{
listen 80;
server_name php2.localhost;
root /home/www/php5.6;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9004; (You can change it to your private IP in the future)
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
By using the above configuration, you can easily switch the different version result of PHP script, moreover, you can use NFS(if you are in a *nix environment) to mount the disk, in this case, you will no need to put files into two folders manually.
As for Fastcgi passing method, I suggest using PORT instead of Socket.
We all know Unix Socket has a better performance due to TCP port uses the whole network stack even on the same machine.
However, the time you save is very little, moreover, you may face this problem when using Socket in a high traffic time,
connect() to unix:/var/run/php5-fpm.sock failed or apr_socket_recv: Connection reset by peer (104)
In addition, TCP port can give you a faster way to manage if you put nginx and php-fpm in separated servers.
I'm using small laptop to edit this post, so codes are not pretty but I tried....
EDITED
Remember to modify your /etc/hosts
to match your hostname (server_name in nginx.conf
)
Best Answer
As soon as I typed the word "include" in my question above, the wheels started spinning in my head.
Turns out you can absolutely just put
allow
anddeny
directives into an include file and they will work just as expected. Best of all, this means I can combine lists of IPs so certain groups of servers can access some directories while others can't.I have it set up like so:
/etc/nginx/includes/admin-ips
/etc/nginx/includes/private-ips
/etc/nginx/includes/testing-ips
/etc/nginx/conf.d/server.conf
Works like a charm.