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

windows nginx php

作者:狂战天下   发布日期:2025-06-28   浏览:98

# Nginx 配置示例,用于与 PHP-FPM 一起工作

server {
    listen 80;
    server_name yourdomain.com;

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

    location / {
        try_files $uri $uri/ =404;
    }

    # PHP 处理配置
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  # 根据你的 PHP 版本调整
        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: 指定服务器的域名或 IP 地址。
  3. root: 设置网站的根目录。
  4. index: 设置默认的索引文件,优先顺序为 index.phpindex.htmlindex.htm
  5. location /: 匹配所有请求,尝试查找文件或目录,如果找不到则返回 404 错误。
  6. location ~ .php$: 匹配以 .php 结尾的文件,使用 FastCGI 协议将请求传递给 PHP-FPM 进程。
    • include snippets/fastcgi-php.conf: 包含 FastCGI 的配置片段。
    • fastcgi_pass: 指定 PHP-FPM 的套接字路径(根据你的 PHP 版本调整)。
    • fastcgi_param SCRIPT_FILENAME: 设置脚本文件的完整路径。
    • include fastcgi_params: 包含其他 FastCGI 参数。
  7. location ~ /.ht: 禁止访问 .htaccess 文件,防止潜在的安全风险。

这个配置文件可以帮助你在 Windows 上使用 Nginx 和 PHP-FPM 来运行 PHP 应用程序。请确保你已经正确安装并配置了 Nginx 和 PHP-FPM。

上一篇:php获取昨天的日期

下一篇:php 获取文件后缀

大家都在看

php session用法

phpisset函数

php后端

php爬虫框架

php读取csv文件

php 三元表达式

php文件加密

php 拆分字符串

php pcntl

php ||

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

Laravel 中文站