安装nginx 方法不限
nginx配置文件如下:
location / {
root html;
index index.html index.php; #:让nginx支持php
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /www; #:这个是php服务器上存放php文件的目录
fastcgi_pass 192.168.206.143:9000; #:这个是php服务器的ip
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
在php服务器上下载php和php组件
yum -y install php php-fpm php-mysql php-gd
然后配置php-fpm文件
vim /etc/php-fpm.d/www.conf
; Start a new pool named ‘www’.
[www]
; 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 address on
; a specific port;
; ‘port’ - to listen on a TCP socket to all addresses 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 = 192.168.206.143:9000 这里写本机的ip
; Set listen(2) backlog. A value of ‘-1’ means unlimited.
; Default Value: -1
;listen.backlog = -1
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1
listen.allowed_clients = 192.168.206.141 这里写nginx的ip
然后在php服务器的目录里写一个php测试文件
mkdir /www
vim /www/index.php
启动php-fpm
systemctl start php-fpm
然后分别登录html和index.php出现不同的结果就表明成功了
192.168.206.141
welcome nginx
192.168.206.141/index.php