0

我的服务器运行在 CentOS 6.3 + Nginx1.4.1 + PHP 5.3.3,</p>

nginx的默认配置是/etc/nginx/default.conf:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

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

我在 /usr/share/nginx/html/phpinfo.php 上写了一个测试脚本

<?php
    phpinfo();
?>

当我执行

curl localhost/phpinfo.php

它返回的php信息如下(部分):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
.center {text-align: center;}
.center table { margin-left: auto; margin-right: auto; text-align: left;}
.center th { text-align: center !important; }
td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccccff; font-weight: bold; color: #000000;}
.h {background-color: #9999cc; font-weight: bold; color: #000000;}
.v {background-color: #cccccc; color: #000000;}
.vr {background-color: #cccccc; text-align: right; color: #000000;}
img {float: right; border: 0px;}
hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
</style>
<title>phpinfo()</title><meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" /></head>
<body><div class="center">
<table border="0" cellpadding="3" width="600">
<tr class="h"><td>
<a href="http://www.php.net/"><img border="0" src="/phpinfo.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42" alt="PHP Logo" /></a><h1 class="p">PHP Version 5.3.3</h1>
</td></tr>
</table><br />
<table border="0" cellpadding="3" width="600">
<tr><td class="e">System </td><td class="v">Linux localhost.localdomain 2.6.32-358.el6.i686 #1 SMP Thu Feb 21 21:50:49 UTC 2013 i686 </td></tr>
<tr><td class="e">Build Date </td><td class="v">Feb 22 2013 02:38:57 </td></tr>

但是,当我在我的电脑上输入 ServerIP/phpinfo.php 时,浏览器无法打开该页面。我已经停止了iptables服务以排除防火墙的影响。

有谁知道如何解决这个问题?哪些错误日志可能会提供一些线索来帮助我找到原因?我已经阅读了 /var/log 上的 nginx 和 php-fpm 的错误日志,但没有任何想法。:-(

/var/log/php-fpm/error.log:

[05-Jun-2013 15:53:39] NOTICE: fpm is running, pid 19292
[05-Jun-2013 15:53:39] NOTICE: ready to handle connections
[05-Jun-2013 16:02:32] NOTICE: Terminating ...
[05-Jun-2013 16:02:32] NOTICE: exiting, bye-bye!
[05-Jun-2013 16:02:32] NOTICE: fpm is running, pid 19387
[05-Jun-2013 16:02:32] NOTICE: ready to handle connections

/var/log/php-fpm/www-error.log(部分):

[05-Jun-2013 16:37:54] PHP Warning:  phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/nginx/html/index.php on line 2
4

4 回答 4

1

nginx 只监听 localhost

server_name  localhost;

您需要将其更改为

 server_name  *;

或者

server_name  youraddress.com;
于 2013-06-05T09:55:55.330 回答
0

您需要提供一个 default_server

在问题中,服务器仅侦听端口80,并且当主机名是localhost. 如nginx's docs中所述,要将一台服务器定义为默认服务器 - 在 listen 指令中使用默认服务器参数:

server {
    listen       80  default_server;
    server_name  example.org;
    ...
}

或者 - 使用*通配符和完整address[:port]语法,使其匹配任何主机名:

server {
    listen       *:80;
    server_name  localhost;
    ...
}

或者,因为无论如何这是默认值 - 只需将其删除:

server {
    server_name  localhost;
    ...
}
于 2013-06-05T14:07:39.843 回答
0

我之前总是使用phpinfo()来测试php环境。刚才我使用其他php脚本,可以成功访问该页面。很奇怪,我的机器上可以访问phpinfo页面,但不能在服务器上访问,可能是系统时区设置的结果。 毕竟谢谢大家的关注!

于 2013-06-06T12:12:50.280 回答
0

将IP和所有名称放入server_name

server_name: localhost xx.xx.xx.xx example.com;

当然xx.xx.xx.xx,请指明您访问服务器的 IP,并且example.com可以是指向您的服务器的名称,在同一行中添加任意数量的名称。

于 2013-06-06T22:52:32.127 回答