CentOS7 Nginx configuration php-fpm

Nginx configuration php-fpm

  1. Installation through yum Nginx and php-fpm. (Mounting step skipped)
  2. 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 {
        }
    }

  1. Verify that the configuration file has an error, the error will resolve the error
sudo nginx -t
  1. Restart Nginx Service
sudo systemctl restart nginx
  1. Access PHP file, whether or not display properly.

Guess you like

Origin blog.csdn.net/sinat_33165594/article/details/91493690