2012-02-18 68 views
2

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

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的查询。我不知道如何解决它。

+1

你为什么同时使用'proxy_pass'和'fastcgi_pass'? – Rifat 2012-02-18 21:43:11

+0

没有它(proxy_pass)他提供我的下载.php文件) – tucnak 2012-02-18 22:03:34

+1

您可能需要删除其中一个位置位置〜\ .php $它不清楚,您使用的是Apache后端还是fastcgi。我认为nginx不能解决这个问题 – ykhrustalev 2012-02-18 22:17:10

回答

1

我一直在Google上搜索和测试我遇到的所有发行版教程,但都没有工作。所以我了解到,你必须为你的发行版咨询正确的文档,否则根本无法工作。所以我发现​​

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

对于那些谁管理红帽网站,这个工作对我来说

  1. 编辑http.conf中,切换到听8080
  2. accordinglly修改nginx.conf按照网站的说明。
  3. 修改虚拟主机文件/etc/httpd/conf.d/httpd-vhosts.conf或其他,只要它可以通过http.conf中包含include指令如下:

$ *了NameVirtualHost:8080

<VirtualHost *:8080> 
    ServerAdmin [email protected] 
    ServerName localhost 
    DocumentRoot /var/www/html/ 
</VirtualHost> 

<VirtualHost *:8080> 
    ServerAdmin [email protected] 
    ServerName site1 
    DocumentRoot /var/www/html/site1 
</VirtualHost> 

<VirtualHost *:8080> 
    ServerAdmin [email protected] 
    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已被评论为对我没有用处)。所有剩余的代码没有变化,但是我的IP服务器名称,在这种情况下,我把主机名称,并且根指令保持不变的根/ usr/share/nginx/html,它不同于虚拟conf文件/ var/www/html /。我的猜测是,作为前端的nginx不知道(甚至不应该)要提供的web文件的位置是Apache。

当我去到任何浏览器,输入:

IP显示nginx的默认页面,所以我想它监听80端口; ip/site1显示site1 ip/site2显示site2

任何其他端口,但80或8080显示连接错误。

关于。