How can PHP files be specified in nginx?

To specify PHP files in nginx, you need to make corresponding settings in the nginx configuration file. Here is a simple example:

  1. Open the configuration file of nginx, typically located at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default.
  2. Locate the server block in the configuration file, usually the section that starts with server { }.
  3. Add the following content in the server block to specify how PHP files should be handled:
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}

The above configuration will route all requests ending in .php to the PHP interpreter for processing.

  1. Restart the nginx service using sudo systemctl reload in the terminal.

Now, you can create PHP files in a specified directory and access them in a browser, where nginx will pass the request to the PHP interpreter for processing.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds