Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

nginx php配置

作者:月下孤魂   发布日期:2026-01-17   浏览:100

# Nginx 配置文件示例,用于处理 PHP 请求

server {
    listen 80;
    server_name yourdomain.com;

    # 网站根目录
    root /var/www/yourdomain.com/html;
    index index.php index.html index.htm;

    # 处理 PHP 文件的 location 块
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # 将 PHP 请求传递给 PHP-FPM
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  # 根据你的 PHP 版本调整此路径

        # 设置必要的 FastCGI 参数
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # 防止访问 .htaccess 文件
    location ~ /\.ht {
        deny all;
    }
}

解释说明:

  1. listen 80: 监听 80 端口,即 HTTP 请求。
  2. server_name: 指定服务器名称或域名。
  3. root: 指定网站的根目录。
  4. index: 指定默认索引文件,支持 index.phpindex.htmlindex.htm
  5. location ~ .php$: 匹配以 .php 结尾的文件,并将这些请求传递给 PHP-FPM 进行处理。
  6. include snippets/fastcgi-php.conf: 包含一些常用的 FastCGI 配置。
  7. fastcgi_pass: 指定 PHP-FPM 的 Unix 套接字路径,确保与 PHP 版本匹配。
  8. fastcgi_param SCRIPT_FILENAME: 设置 FastCGI 参数,告诉 PHP-FPM 要执行的脚本文件路径。
  9. include fastcgi_params: 包含更多的 FastCGI 参数配置。
  10. location ~ /.ht: 禁止访问 .htaccess 文件,防止潜在的安全风险。

上一篇:php获取ip

下一篇:php session设置过期时间

大家都在看

php session用法

php 定义常量

phpisset函数

php html转图片

php后端

php爬虫框架

php读取csv文件

php+mysql动态网站开发

phpmyadmin docker

php session id

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站