NginX 不执行 PHP

2023-11-22

我已经尝试过数十种可能的解决方案来解决这个问题,但找不到任何有效的解决方案。基本上,PHP 文件不会在我的 NginX + PHP_fpm + Ubuntu 14 服务器上执行。我拥有所有软件包,并且它们正在运行。我已经清除了浏览器缓存等,但还没有任何效果。我感谢所有的帮助!

截至目前,如果我尝试访问 PHP 文件,GET 会将其作为 HTML 文件返回,但不会执行脚本。

这是我的 nginx.conf 文件:

worker_processes 1;
worker_rlimit_nofile 8192;

events {
 worker_connections  3000;
}

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

http {
   include       /etc/nginx/mime.types;
   #default_type  application/octet-stream;
   default_type text/html;

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';

   access_log  /var/log/nginx/access.log  main;

   sendfile        on;
   #tcp_nopush     on;

   keepalive_timeout  65;

   #gzip  on;

   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/sites-enabled/*;
}

这是我的 /sites-available/default 文件:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /usr/share/nginx/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
              root /usr/share/nginx/html;
      }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        include snippets/fastcgi-php.conf;

        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        #fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny all;
    #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen [::]:80;
#
#    server_name example.com;
#
#    root /var/www/example.com;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}

这是我的服务器配置文件:

server {

   listen 8000 default_server;

   listen [::]:8000 default_server ipv6only=on;

    root /var/www/html;
    #index index.php index.html index.htm;

   #location / {

     #index index.php index.html index.htm;

   #}
}

正如你所看到的,我一直在研究这些文件。但无济于事。


好的,根据我们的评论,您需要将此部分添加到您的 nginx 配置中,以便服务器配置侦听:8000。

该正则表达式告诉 nginx,每当它收到对以 .php 结尾的文件的 URL 的请求时,将其发送到 fastcgi 进程。否则,它将默认返回 /var/www/html 中匹配的原始文件。

希望有帮助。

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    try_files $uri =404;
    include snippets/fastcgi-php.conf;

    # With php5-cgi alone:
    #fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    #fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_index index.php;
    include fastcgi_params;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NginX 不执行 PHP 的相关文章

随机推荐

  • 固定页眉

    我以前从未处理过 CSS 但现在我必须处理 我正在开发一些 HTML 代码 一个网站的草图 并且有 CSS 问题 我希望我的标题位于固定位置 我的意思是它始终应该位于网站的顶部 即使有太多内容以至于网站必须滚动才能看到所有内容 我尝试过一些
  • 删除控制器/类中的 HttpServletRequest 参数的最佳方法?

    我有一个情况 我需要将 HTTP 请求对象重定向到其他控制器 类以进行进一步处理 问题是 在某些控制器中 我想更好地控制我转发到下一个类的参数 修改 编辑 删除它们 所以 我想知道是否有一个好的实践 模式来实现对 HTTP 请求参数的基本控
  • Android 4 ICS 上带有 SSL 客户端证书的 WebView

    我对 Android 上的本机 WebView 有问题 我需要使用 SSL 客户端证书对站点进行身份验证 Android WebView 似乎不支持这个 作为解决方法 我使用了 WebView 的修改版本 https github com
  • java中String转int数组

    我有一根绳子 String arr 1 2 ie 1 2 就像一个单一的字符串 我该如何转换这个arrjava中的int数组 String arr 1 2 String items arr replaceAll replaceAll rep
  • JavaScript 中的数字是不可变的吗? [复制]

    这个问题在这里已经有答案了 可能的重复 javascript 数字 不可变 我读了道格拉斯 克罗克福德 Douglas Crockford 的书 JavaScript the Good Parts 它说 JavaScript 中的数字是不可
  • 如何在不输入任何内容的情况下触发角度解析器

    正如主题所述 我如何触发在一个内部发生的动作 modelController parsers 没有用户输入 我能想到的唯一方法是将它们包装在函数中并调用它 但是有没有更好的方法来触发 pseudo modelController trigg
  • 对齐属性 已弃用

    不久前我发现中心标签已被弃用 这是可以理解的 因为 HTML 是用来构建内容的 而不是用来格式化的 但为什么对齐属性也被弃用了呢 属性可用于格式化 我明白CSS可以用 但并不是每个人都懂CSS 更糟糕的是 文本对齐 居中 and 左边距 自
  • 源代码不可用时的访问者模式实现

    考虑的原因之一访客模式 这种分离的实际结果是能够向现有对象结构添加新操作 而无需修改这些结构 假设您没有第三方库的源代码 并且您已经添加了对相关对象的一项操作 由于您没有对象 因此无法修改您的元素 第三方类 来添加访问者 在这种情况下 双重
  • 使用后备语言检索 i18n 数据

    我必须从数据库中获取 i18n 文本 默认语言为英语 其文本为一切 但非英语语言不一定具有所有所需的翻译 如果某个实体 键的非英语翻译在数据库中不可用 那么我希望它返回英语文本 所以 英语是fallback这里的语言 i18n 文本表如下所
  • 如何使用 CMake 有选择地链接到静态或动态 boost 库?

    我有一个 CMake 项目 有时想针对静态 boost 库进行编译 但我也希望能够轻松地使用 cmake GUI 中的动态库 在我的顶级 CMakeLists txt 中 我有以下内容 option USE STATIC BOOST Bui
  • jQuery 中的节流事件调用

    我有一个keyup事件绑定到需要大约四分之一秒才能完成的函数 search keyup function code that takes a little bit to complete 当用户键入整个单词或以其他方式快速按键时 该函数将连
  • 使用pyspark,在hadoop文件系统上读/写2D图像

    我希望能够在 hdfs 文件系统上读取 写入图像并利用 hdfs 局部性 我有一个图像集合 其中每个图像由以下内容组成 uint16 的二维数组 存储为 xml 文件的基本附加信息 我想通过 hdfs 文件系统创建一个存档 并使用 Spar
  • jQuery Mobile 破坏了我的网站

    当我仅使用移动触摸屏设备时 我会在网站上加载 jQuery Mobile 当我这么做的时候 它把一切都搞乱了 例如 选择菜单也不能正常工作 页面底部会出现 正在加载 正在加载 未定义 字样 我知道我错过了一些东西 但不知道是什么 关于我可能
  • JavaScript 对象的生命周期和内存泄漏

    我对此进行了相当多的研究 但主要是通过将其他问题拼凑在一起 这仍然留下了一些疑问 在一个不随时刷新浏览器页面并且可能会运行相当长一段时间 几个小时 而不关闭的应用程序中 假设刷新页面或导航到另一个页面会重新启动 js 代码 确保对象的最佳方
  • TypeScript:具有可选值的可区分联合

    给定以下类型 interface FullName fullName string interface Name firstName string lastName string type Person FullName Name cons
  • 友元函数无法构造该类的唯一指针

    我有一个特定的设计策略 其中我的类的构造函数是私有的 并且只能由该类的朋友构建 在朋友函数中 我尝试使用以下命令创建我的类的 unique pointerstd make unique但它不编译 我的 VC12 编译器抱怨 c progra
  • 编写并编织一份按变量与特殊字符 (å æ ø) 分割的 PDF 报告 - 编码问题

    我尝试使用基于分组变量的部分来生成一份 PDF 报告brew and knitr 我的分组变量可能包含特殊字符 元音变音 例如 仅文档标题中的变音符号可以很好地处理 usepackage utf8 inputenc 参见下面的示例 但是 分
  • 为什么 jquery .height() 在 chrome 上得到不同的结果?

    这是 chrome 显示 div 的宽度和高度的方式 这是正确的 事实上高度是 1466 但是 如果我这样做 document ready function console log container altezza fisso heigh
  • Javascript 到 Jquery,在输入 onclick 中添加文本

    我怎样才能将这个javascript代码更改为JQuery 当用户单击链接时 文本会自动添加到输入中 这是 HTML
  • NginX 不执行 PHP

    我已经尝试过数十种可能的解决方案来解决这个问题 但找不到任何有效的解决方案 基本上 PHP 文件不会在我的 NginX PHP fpm Ubuntu 14 服务器上执行 我拥有所有软件包 并且它们正在运行 我已经清除了浏览器缓存等 但还没有