Skip to content

Commit ca0b77f

Browse files
committed
- nginx: Changed ispconfig and apps vhost from using PHP-FPM TCP connections to sockets.
1 parent f19eb67 commit ca0b77f

File tree

11 files changed

+81
-31
lines changed

11 files changed

+81
-31
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,13 @@ public function install_ispconfig()
942942
$content = str_replace('{fastcgi_ssl}', 'off', $content);
943943
}
944944

945-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
945+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
946+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
947+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
948+
$fpm_socket = $socket_dir.'ispconfig.sock';
949+
950+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
951+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
946952

947953
wf($vhost_conf_dir.'/ispconfig.vhost', $content);
948954

@@ -952,7 +958,8 @@ public function install_ispconfig()
952958
// Dont just copy over the php-fpm pool template but add some custom settings
953959
$content = rf('tpl/php_fpm_pool.conf.master');
954960
$content = str_replace('{fpm_pool}', 'ispconfig', $content);
955-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
961+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
962+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
956963
$content = str_replace('{fpm_user}', 'ispconfig', $content);
957964
$content = str_replace('{fpm_group}', 'ispconfig', $content);
958965
wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);

install/dist/lib/gentoo.lib.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,20 +642,27 @@ public function configure_apps_vhost()
642642
} else {
643643
$apps_vhost_ip = $conf['web']['apps_vhost_ip'].':';
644644
}
645+
646+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
647+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
648+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
649+
$fpm_socket = $socket_dir.'apps.sock';
645650

646651
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content);
647652
$content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content);
648653
$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content);
649654
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
650-
$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
655+
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
656+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
651657

652658
wf($vhost_conf_dir.'/apps.vhost', $content);
653659

654660
// PHP-FPM
655661
// Dont just copy over the php-fpm pool template but add some custom settings
656662
$content = rf('tpl/apps_php_fpm_pool.conf.master');
657663
$content = str_replace('{fpm_pool}', 'apps', $content);
658-
$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
664+
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
665+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
659666
$content = str_replace('{fpm_user}', $apps_vhost_user, $content);
660667
$content = str_replace('{fpm_group}', $apps_vhost_group, $content);
661668
wf($conf['nginx']['php_fpm_pool_dir'].'/apps.conf', $content);
@@ -918,7 +925,13 @@ public function install_ispconfig()
918925
$content = str_replace('{fastcgi_ssl}', 'off', $content);
919926
}
920927

921-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
928+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
929+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
930+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
931+
$fpm_socket = $socket_dir.'ispconfig.sock';
932+
933+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
934+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
922935

923936
wf($vhost_conf_dir.'/ispconfig.vhost', $content);
924937

@@ -928,7 +941,8 @@ public function install_ispconfig()
928941
// Dont just copy over the php-fpm pool template but add some custom settings
929942
$content = rf('tpl/php_fpm_pool.conf.master');
930943
$content = str_replace('{fpm_pool}', 'ispconfig', $content);
931-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
944+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
945+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
932946
$content = str_replace('{fpm_user}', 'ispconfig', $content);
933947
$content = str_replace('{fpm_group}', 'ispconfig', $content);
934948
wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);

install/dist/lib/opensuse.lib.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,13 @@ public function install_ispconfig()
976976
$content = str_replace('{fastcgi_ssl}', 'off', $content);
977977
}
978978

979-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
979+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
980+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
981+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
982+
$fpm_socket = $socket_dir.'ispconfig.sock';
983+
984+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
985+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
980986

981987
wf($vhost_conf_dir.'/ispconfig.vhost', $content);
982988

@@ -986,7 +992,8 @@ public function install_ispconfig()
986992
// Dont just copy over the php-fpm pool template but add some custom settings
987993
$content = rf('tpl/php_fpm_pool.conf.master');
988994
$content = str_replace('{fpm_pool}', 'ispconfig', $content);
989-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
995+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
996+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
990997
$content = str_replace('{fpm_user}', 'ispconfig', $content);
991998
$content = str_replace('{fpm_group}', 'ispconfig', $content);
992999
wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);

install/lib/installer_base.lib.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,20 +1472,27 @@ public function configure_apps_vhost() {
14721472
} else {
14731473
$apps_vhost_ip = $conf['web']['apps_vhost_ip'].':';
14741474
}
1475+
1476+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
1477+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
1478+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
1479+
$fpm_socket = $socket_dir.'apps.sock';
14751480

14761481
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content);
14771482
$content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content);
14781483
$content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content);
14791484
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
1480-
$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
1485+
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
1486+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
14811487

14821488
wf($vhost_conf_dir.'/apps.vhost', $content);
14831489

14841490
// PHP-FPM
14851491
// Dont just copy over the php-fpm pool template but add some custom settings
14861492
$content = rf('tpl/apps_php_fpm_pool.conf.master');
14871493
$content = str_replace('{fpm_pool}', 'apps', $content);
1488-
$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
1494+
//$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
1495+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
14891496
$content = str_replace('{fpm_user}', $apps_vhost_user, $content);
14901497
$content = str_replace('{fpm_group}', $apps_vhost_group, $content);
14911498
wf($conf['nginx']['php_fpm_pool_dir'].'/apps.conf', $content);
@@ -1808,8 +1815,14 @@ public function install_ispconfig() {
18081815
$content = str_replace('{fastcgi_ssl}', 'off', $content);
18091816
}
18101817

1811-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
1812-
1818+
$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
1819+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
1820+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
1821+
$fpm_socket = $socket_dir.'ispconfig.sock';
1822+
1823+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
1824+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
1825+
18131826
wf($vhost_conf_dir.'/ispconfig.vhost', $content);
18141827

18151828
unset($content);
@@ -1818,7 +1831,8 @@ public function install_ispconfig() {
18181831
// Dont just copy over the php-fpm pool template but add some custom settings
18191832
$content = rf('tpl/php_fpm_pool.conf.master');
18201833
$content = str_replace('{fpm_pool}', 'ispconfig', $content);
1821-
$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
1834+
//$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
1835+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
18221836
$content = str_replace('{fpm_user}', 'ispconfig', $content);
18231837
$content = str_replace('{fpm_group}', 'ispconfig', $content);
18241838
wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);

install/tpl/apps_php_fpm_pool.conf.master

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[{fpm_pool}]
22

3-
listen = 127.0.0.1:{fpm_port}
4-
5-
listen.allowed_clients = 127.0.0.1
3+
listen = {fpm_socket}
4+
listen.owner = {fpm_user}
5+
listen.group = {fpm_group}
6+
listen.mode = 0660
67

78
user = {fpm_user}
89
group = {fpm_group}

install/tpl/nginx_apps.vhost.master

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server {
1717
location ~ \.php$ {
1818
try_files $uri =404;
1919
include /etc/nginx/fastcgi_params;
20-
fastcgi_pass 127.0.0.1:{fpm_port};
20+
fastcgi_pass unix:{fpm_socket};
2121
fastcgi_index index.php;
2222
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2323
fastcgi_param PATH_INFO $fastcgi_script_name;
@@ -38,7 +38,7 @@ server {
3838
try_files $uri =404;
3939
root /usr/share/;
4040
include /etc/nginx/fastcgi_params;
41-
fastcgi_pass 127.0.0.1:{fpm_port};
41+
fastcgi_pass unix:{fpm_socket};
4242
fastcgi_index index.php;
4343
fastcgi_param SCRIPT_FILENAME $request_filename;
4444
}
@@ -57,7 +57,7 @@ server {
5757
try_files $uri =404;
5858
root /usr/share/;
5959
include /etc/nginx/fastcgi_params;
60-
fastcgi_pass 127.0.0.1:{fpm_port};
60+
fastcgi_pass unix:{fpm_socket};
6161
fastcgi_index index.php;
6262
fastcgi_param SCRIPT_FILENAME $request_filename;
6363
}

install/tpl/nginx_ispconfig.vhost.master

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ server {
1919
location ~ \.php$ {
2020
try_files $uri =404;
2121
include /etc/nginx/fastcgi_params;
22-
fastcgi_pass 127.0.0.1:{fpm_port};
22+
fastcgi_pass unix:{fpm_socket};
2323
fastcgi_index index.php;
2424
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2525
fastcgi_param PATH_INFO $fastcgi_script_name;
@@ -40,7 +40,7 @@ server {
4040
# try_files $uri =404;
4141
# root /usr/share/;
4242
# include /etc/nginx/fastcgi_params;
43-
# fastcgi_pass 127.0.0.1:{fpm_port};
43+
# fastcgi_pass unix:{fpm_socket};
4444
# {ssl_comment}fastcgi_param HTTPS {fastcgi_ssl};
4545
# fastcgi_index index.php;
4646
# fastcgi_param SCRIPT_FILENAME $request_filename;
@@ -60,7 +60,7 @@ server {
6060
# try_files $uri =404;
6161
# root /usr/share/;
6262
# include /etc/nginx/fastcgi_params;
63-
# fastcgi_pass 127.0.0.1:{fpm_port};
63+
# fastcgi_pass unix:{fpm_socket};
6464
# {ssl_comment}fastcgi_param HTTPS {fastcgi_ssl};
6565
# fastcgi_index index.php;
6666
# fastcgi_param SCRIPT_FILENAME $request_filename;

install/tpl/php_fpm_pool.conf.master

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[{fpm_pool}]
22

3-
listen = 127.0.0.1:{fpm_port}
4-
5-
listen.allowed_clients = 127.0.0.1
3+
listen = {fpm_socket}
4+
listen.owner = {fpm_user}
5+
listen.group = {fpm_group}
6+
listen.mode = 0660
67

78
user = {fpm_user}
89
group = {fpm_group}

server/conf/nginx_apps.vhost.master

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server {
1717
location ~ \.php$ {
1818
try_files $uri =404;
1919
include /etc/nginx/fastcgi_params;
20-
fastcgi_pass 127.0.0.1:{fpm_port};
20+
fastcgi_pass unix:{fpm_socket};
2121
fastcgi_index index.php;
2222
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2323
fastcgi_param PATH_INFO $fastcgi_script_name;
@@ -38,7 +38,7 @@ server {
3838
try_files $uri =404;
3939
root /usr/share/;
4040
include /etc/nginx/fastcgi_params;
41-
fastcgi_pass 127.0.0.1:{fpm_port};
41+
fastcgi_pass unix:{fpm_socket};
4242
fastcgi_index index.php;
4343
fastcgi_param SCRIPT_FILENAME $request_filename;
4444
}
@@ -57,7 +57,7 @@ server {
5757
try_files $uri =404;
5858
root /usr/share/;
5959
include /etc/nginx/fastcgi_params;
60-
fastcgi_pass 127.0.0.1:{fpm_port};
60+
fastcgi_pass unix:{fpm_socket};
6161
fastcgi_index index.php;
6262
fastcgi_param SCRIPT_FILENAME $request_filename;
6363
}

server/plugins-available/apps_vhost_plugin.inc.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ function update($event_name,$data) {
117117
} else {
118118
$apps_vhost_ip = $web_config['apps_vhost_ip'].':';
119119
}
120+
121+
$socket_dir = escapeshellcmd($web_config['php_fpm_socket_dir']);
122+
if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
123+
if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
124+
$fpm_socket = $socket_dir.'apps.sock';
120125

121126
$content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content);
122127
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content);
123128
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content);
124129
$content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
125-
$content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $content);
130+
//$content = str_replace('{fpm_port}', $web_config['php_fpm_start_port']+1, $content);
131+
$content = str_replace('{fpm_socket}', $fpm_socket, $content);
126132
}
127133

128134
file_put_contents("$vhost_conf_dir/apps.vhost", $content);

0 commit comments

Comments
 (0)