关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
7年前关闭。
Improve this question
我想做的事:
让 Nginx 在使用 debootstrap 创建的 chroot jail 中通过 FastCGI (FPM) 提供 PHP 文件。
问题:
每个将主机名解析为 IP 地址的函数都会失败,并显示 php_network_getaddresses: getaddrinfo failed: Name or service not known
.奇怪的是,从 chrooted shell 解析主机名没有问题。
到目前为止我做了什么:
nameserver 8.8.8.8
和 nameserver 8.8.4.4
到/etc/resolv.conf。 (我以前没有这样做过,因为名称服务器是由 DHCP 服务器正确提供的!) domain localhost
1 到/etc/resolv.conf 和 127.0.0.1 localhost
1 到/etc/hosts。 不用说实际上没有解决问题,所以请帮助我。
重现此所需的所有步骤:
vi /etc/apt/sources.list
并使文件看起来像这样:deb http://ftp.de.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.de.debian.org/debian/ wheezy main contrib non-free
deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main
deb http://ftp.de.debian.org/debian/ wheezy-updates main
deb-src http://ftp.de.debian.org/debian/ wheezy-updates main
aptitude update && aptitude -y full-upgrade
aptitude -y install debootstrap nginx php5-fpm
debootstrap wheezy /srv/localhost http://ftp.de.debian.org/debian/
1 mkdir /srv/localhost/srv/www
1echo "<?php fsockopen('ftp.de.debian.org'); ?>" > /srv/localhost/srv/www/index.php
1chown -R 33:33 /srv/localhost/srv/www
1 vi /etc/nginx/sites-available/localhost
1并使文件看起来像这样1:server {
listen 127.0.0.1:80;
server_name localhost;
root /srv/localhost/srv/www;
index index.html index.htm index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/localhost.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ {
access_log off;
}
location = /favicon.ico {
log_not_found off;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
ln -s /etc/nginx/sites-available/localhost /etc/nginx/sites-enabled/
1 vi /etc/nginx/fastcgi_params
并使文件看起来像这样:fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
vi /etc/php5/fpm/pool.d/localhost.conf
1并使文件看起来像这样1:[localhost]
user = www-data
group = www-data
listen = /var/run/localhost.sock
listen.allowed_clients = 127.0.0.1
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 300s
pm.max_requests = 500
;access.log = log/$pool.access.log
;access.format = "%R - %u %t \"%m %r\" %s"
chroot = /srv/localhost/srv
chdir = /
;catch_workers_output = yes
;security.limit_extensions = .php .php3 .php4 .php5
php_flag[display_errors] = on
php_admin_flag[log_errors] = on
php_admin_value[error_log] = /var/log/php.log
php_admin_value[memory_limit] = 32M
php_admin_value[session.save_path] = /tmp
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
rm /etc/nginx/sites-enabled/default /etc/php5/fpm/pool.d/wwww.conf
service php5-fpm restart && service nginx restart
wget -qO- http://localhost
1 个打印件:<br />
<b>Warning</b>: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in <b>/www/index.php</b> on line <b>1</b><br />
<br />
<b>Warning</b>: fsockopen(): unable to connect to ftp.de.debian.org:80:-1 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in <b>/www/index.php</b> on line <b>1</b><br />
chroot /srv/localhost/
1ping -c1 ftp.de.debian.org
打印:PING ftp.de.debian.org (141.76.2.4) 56(84) bytes of data.
64 bytes from ftp.de.debian.org (141.76.2.4): icmp_req=1 ttl=56 time=15.1 ms
--- ftp.de.debian.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 15.137/15.137/15.137/0.000 ms
1 我的实际域的所有实例都已替换为 localhost,而我的实际 IP 地址的所有实例均已替换为 127.0.0.1。
2 我已导出 Oracle® VirtualBox 设备并将其上传到 Mega.co.nz (root密码就是密码)给所有真正非常渴望在这里帮助我的人。
最佳答案
我不知道为什么会发生这种情况,但是您可能可以通过使用 strace 找出答案。要安装 strace,您需要执行 apt-get install strace
.然后你用 ps ax | grep nginx
得到 nginx 的 PID .然后对于实际的跟踪:
strace -f -s 1024 -p PIDOFNGINX -o /tmp/trace.out
然后你启动
wget -qO- http://localhost
,停止 nginx(或杀死 strace),然后查看/tmp/trace.out 以及它在哪里引发错误。您的 chroot 中可能缺少一些库。编辑:
你写你所做的事情的方式实际上并没有在chroot中执行测试ping。那应该是:
chroot /srv/localhost /bin/ping -c1 ftp.de.debian.org
然后,您实际上可以 strace 那个 ping,然后它会包含更少的来自 nginx 的东西。这将要求 ping 命令也位于 chroot 中(无论如何都需要它来测试它),包括它依赖的库等。
关于php - 为什么 chrooted PHP (FPM) 在 chrooted shell 没有问题时会出现 DNS 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155497/