Nginx configuration php-fpm
- Installation through yum Nginx and php-fpm. (Mounting step skipped)
- Edit the Nginx configuration file, add the following at the server in http:
# 配置php-fpm
location ~ \.php$ {
root /var/www/html; #指定php的根目录
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Modifications Modifications after:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
# 配置php-fpm
location ~ \.php$ {
root /var/www/html; #指定php的根目录
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
- Verify that the configuration file has an error, the error will resolve the error
sudo nginx -t
- Restart Nginx Service
sudo systemctl restart nginx
- Access PHP file, whether or not display properly.