centos+nginx+php配置简介
Jun 06, 2016 pm 07:49 PMnginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。 打开nginx.conf, 找到location / 修改如下: location / { root /var/www; index index.php index.html index.htm; } 找到location ~ .php$,修改如下: location ~ .php$ { root /var/www;
nginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。
打开nginx.conf,
找到location / 修改如下:
location / {
root /var/www;
index index.php index.html index.htm;
}
找到location ~ .php$,修改如下:
location ~ .php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}
root:设置PHP脚本的根目录
fastcgi_pass:处理PHP脚本的端口,这里监听9001
fastcgi_index :索引文件
fastcgi_param:php脚本路径
设置完之后,还需要配置php-fpm.conf,进入你的php安装目录下的etc文件夹,将php-fpm.conf.default重命名为php-fpm.conf,双击打开,修改listen为9001。
启动终端,cd进入php安装目录的sbin文件夹,使用./php-fpm命令启动fpm,如果启动报错,打开php-fpm.conf,去掉如下语句前的注视,然后重启php-fpm
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
配置nginx和php-fpm开机自启动:
打开/etc/rc.local,在末尾添加
ulimit -SHn 65535
/var/web/php/sbin/php-fpm
/var/web/nginx/sbin/nginx
保存文件,重启。
注意把/var/web/php和/var/web/nginx修改成你自己的php/nginx安装目录。
在var/www目录下新建index.php,写入代码:
phpinfo();
?>
访问:http://localhost,出现php配置信息界面,大功告成!
PS:手动启动nginx,打开终端,cd进入nginx的sbin目录,使用./nginx命令启动nginx

Article chaud

Outils chauds Tags

Article chaud

Tags d'article chaud

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Comment autoriser l'accès au réseau externe au serveur Tomcat

Quelles sont les commandes de démarrage et d'arrêt de nginx ?

Comment résoudre le problème de nginx lors de l'accès au site Web

Bienvenue sur nginx !Comment le résoudre ?

Comment déployer le projet nodejs sur le serveur

Comment communiquer entre les conteneurs Docker
