【问题标题】:nginx and apache (php)nginx 和 apache (php)
【发布时间】:2012-02-18 21:38:03
【问题描述】:

我已经设置了我的 nginx,但现在我的虚拟主机上的每个 *.php 文件都返回 500 内部服务器错误。

server {
listen   tucnak.dev:80; ## listen for ipv4; this line is default and implied

root /home/tucnak/Web/Lab;
index index.php index.html;

server_name tucnak.dev;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html
    try_files $uri $uri/ /index.html;
}

location /doc {
    root /usr/share;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}

location /images {
    root /usr/share;
    autoindex off;
}

#error_page 404 /404.html;

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

location ~ \.php$ {
    proxy_pass http://127.0.0.1;
}

location  ~ \.php$ {
        set $php_root /home/tucnak/Web/Lab;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

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

我的错误在哪里?我的 php 文件完全正确!

 <?php echo("Hello!"); ?>

我是 nginx 的新手,需要帮助。在 apache2 之后 - 我很困惑!

UPD:我认为 nginx 没有成功查询 apache。我不知道如何解决它。

【问题讨论】:

  • 你为什么同时使用proxy_passfastcgi_pass
  • 没有它(proxy_pass)他提供我下载.php文件)
  • 您可能需要删除其中一个位置 location ~ \.php$ 不清楚,您使用的是 apache 后端还是 fastcgi。我认为 nginx 也无法解决这个问题
  • 我很困惑。我已经在新机器上安装了 nginx 和 apache2。没有 apache2 配置。那么,我该怎么办?
  • 您收到error 500,因为您的位置不明确。而且,没有proxy_pass,它正在下载你的php文件,因为我认为你的apache没有启用fast_cgi

标签: php apache2 nginx


【解决方案1】:

我一直在谷歌搜索和测试我遇到的所有发行版教程,但没有一个有用。因此,我了解到必须为您的发行版查阅正确的文档,否则它将无法正常工作。于是我找到了this one

我有运行 Apache 2.2 的 RHE5.7 Tikanga。两个站点在端口 8080 和 nginx-1.0.14-1.el5.ngx 80 上运行。我的意思是我有两个目录链接到 /var/www/html/site1 和 /var/www/html/site2。两者都在 php 5 中。

对于那些管理 Red Hat 网站的人来说,这对我有用

  1. 编辑 http.conf 并更改为 Listen 8080
  2. 根据站点说明相应地修改 nginx.conf。
  3. 修改虚拟主机文件 /etc/httpd/conf.d/httpd-vhosts.conf 或其他,只要它可以被 http.conf 包含指令包含如下:

$ NameVirtualHost *:8080

<VirtualHost *:8080>
    ServerAdmin me@mydomain.com
    ServerName localhost
    DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin me@mydomain.com
    ServerName site1
    DocumentRoot /var/www/html/site1
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin sleepy@nightmare.com
    ServerName site2
    DocumentRoot /var/www/html/site2
</VirtualHost>`

/etc/nginx/nginx.conf - 修正 在此文件之上:

..... $worker_rlimit_nofile 20480; ....

    gzip_buffers 32 8k;
    gzip_comp_level   6;
    gzip_http_version 1.0;
    gzip_min_length   1;

#include /etc/nginx/conf.d/*.conf 行已被注释,因为这对我来说没用)。所有剩下的代码都没有改变,但是我的 IPservername,在这种情况下我放了 hostname,并且根指令保持与根 / usr/share/nginx/html,与虚拟配置文件/var/www/html/中的不同。我的猜测是,作为前端的 nginx 不知道(甚至不应该)要提供的 web 文件在哪里,但 Apache。

当我打开任何浏览器并输入:

ip 显示 nginx 默认页面,所以我猜它正在监听 80 端口; ip/site1 显示 site1 ip/site2 显示site2

除 80 或 8080 以外的任何其他端口都会显示连接错误。

问候。

【讨论】:

    猜你喜欢
    • 2011-05-05
    • 2011-05-31
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 2018-09-12
    • 2014-09-25
    • 2012-10-29
    相关资源
    最近更新 更多