我们都知道php-fpm的默认监听端口,也就是启动端口是9000,最近在群里经常看有人问说感觉默认端口9000不太安全,能不能修改成别的端口,那样也相对安全。
其实修改这个启动端口非常简单的,只需要在安装目录下面找到配置文件夹下面的配置文件,在配置文件里面把默认端口9000修改成你需要的端口便可以。
我这里的php安装目录:/usr/local/php,配置文件夹在安装目录的etc/php-fpm.d/下面的已conf为后缀的文件,一般在安装时我们设置成了www.conf。
[root@localhost php]# vi etc/php-fpm.d/www.conf
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr/local/php) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nobody
group = nobody
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
把 listen = 127.0.0.1:9000 后面的端口号9000换成你需要的端口,然后重启php,重启命令如下;
[root@localhost php]# pkill php-fpm #关闭php
[root@localhost php]# /usr/local/bin/php-fpm #启动php,或直接命令:sbin/php-fpm
[root@localhost php]# netstat -ntpl |grep php-fpm
tcp 0 0 127.0.0.1:8999 0.0.0.0:* LISTEN 4821/php-fpm: maste
我把默认启动的监听端口修改成了8999,最后一步就是配置nginx的.php请求被传送到后端的php-fpm模块,把端口由默认的9000改成我们修改后的8999;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:8999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
最后就是nginx配置更改了,别忘记重新加载nginx配置文件。
最新评论
感谢
能不能屏蔽掉刷流量的,统计工具显示全部都是
路过学习了
好像不太行啊 加载不出来啊
好文章
是否可以 实现 判断手机端跳转 而网址不变呢
你好
感谢分享,我也遇到这个了,根据你的提示,屏蔽掉了