安装nginx + php-fpm 环境搭建 和nginx运行环境配置
-- 一、安装Nginx
安装前先装这几个
yum -y install gcc pcre pcre-devel openssl openssl-devel
下载nginx的安装包解压
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx
make
make install
开启的方法
/usr/local/nginx/sbin/nginx -s reload
ps aux|grep nginx //查看nginx PID进程号
kill -INI PID //关闭nginx
kill -HUP PID //平滑重启
二、安装php-fpm
yum install php php-fpm
开启的方法
service php-fpm start
配置nginx
打开配置文件
vi /usr/local/nginx/conf/nginx.conf
找到第一个 server
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www; #修改这里,网站路径
index index.php index.html index.htm;
}
#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; #修改这里,网站路径
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name; #修改这里,网站路径
include fastcgi_params;
}
deny access to .htaccess files, if Apache's document root
concurs with nginx's one
#location ~ /.ht {
deny all;
#}
}
location ~ .php$ 要开启