假设我拥有example.com
.
然后我在to上创建一个A
记录。test.example.com
1.1.1.1
然后我在to上创建一个NS
记录。test.example.com
ns1.anotherdnshost.com
在另一个 DNS 主机上,我将A
根 ( test.example.com
) 的记录添加到2.2.2.2
.
客户端查询时,会返回test.example.com
哪条记录?A
哪个会是更“主导”的A
记录?这样的设置有效吗?
假设我拥有example.com
.
然后我在to上创建一个A
记录。test.example.com
1.1.1.1
然后我在to上创建一个NS
记录。test.example.com
ns1.anotherdnshost.com
在另一个 DNS 主机上,我将A
根 ( test.example.com
) 的记录添加到2.2.2.2
.
客户端查询时,会返回test.example.com
哪条记录?A
哪个会是更“主导”的A
记录?这样的设置有效吗?
我在 nginx 1.2.8 上启用了 gzip,但出于某种原因,它没有压缩任何东西。
Nginx 安装信息:
nginx version: nginx/1.2.8
built by gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.2.8 --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre --conf-path=/etc/nginx/nginx.conf --add-module=../headers-more-nginx-module-0.19rc1
配置:
user www-user;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10M;
sendfile on;
keepalive_timeout 65;
more_clear_headers "Server";
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
server {
server_name test.com;
root /www;
index index.php index.html index.htm;
listen 80 default_server;
rewrite ^/(.*)/$ /$1 permanent; #remove trailing slash
#charset koi8-r;
#access_log logs/host.access.log main;
include general/*.conf;
#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 html;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
我正在尝试发送一个简单的静态 css 文件。在我的 nginx 配置中,text/css
包含在gzip_types
.
当我尝试使用 Firefox 获取文件时,fiddler 显示接收到的内容未经过 gzip 压缩:
请求标头:
GET http://test.com/test.css HTTP/1.1
Host: nextdreamtest2.com
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __utma=237624223.1052931239.1362029000.1365467381.1365469205.16; __utmz=237624223.1362029000.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=237624223; __utmb=237624223
Proxy-Authorization: Basic cHJveHk6RTRRWlNlY0JLU3o0OFh4cWpLNkg=
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
响应标头:
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 01:35:07 GMT
Content-Type: text/css
Last-Modified: Thu, 31 May 2012 08:50:00 GMT
Connection: keep-alive
Content-Length: 1688
请注意,即使在服务器上启用了 gzip,也没有Content-Encoding: gzip
标头,并且内容类型是配置为 gzip 的类型。
经过更多的调查,我现在更加困惑了。我在运行 nginx 的机器上尝试了 FireFox 20.0(Ubuntu 12.10),并且文件被正确压缩:
Connection keep-alive
Content-Encoding gzip <------------------------------
Content-Type text/html
Date Tue, 09 Apr 2013 04:23:08 GMT
Set-Cookie 200ceb26807d6bf99fd6f4f0d1ca54d4=7hjir1h44g3dq8hlsihdsrn9v5; path=/; HttpOnly
Transfer-Encoding chunked <---------------------
但是,如果我尝试使用 IE10、FireFox 20 和 Chrome 26 以及 Fiddler 检查我的 Windows 8 计算机上的标头以访问服务器,响应永远不会压缩!
Connection keep-alive
Content-Length 2192 <------------------
Content-Type text/html
Date Tue, 09 Apr 2013 04:27:16 GMT
这非常奇怪,因为我在我的 nginx.conf 中没有看到任何会歧视 Windows 8 机器的东西。
是什么原因造成的?
我正在使用 CURL 测试对我的 nginx 服务器的 HEAD 请求。提供的文件是一个简单的PHP
文件。
如果我使用GET
:
$ curl -XGET http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 00:35:35 GMT
Content-Type: text/html
Connection: keep-alive
Content-Length: 72080
但是,如果我使用HEAD
:
$ curl -XHEAD http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 00:37:00 GMT
Content-Type: text/html
Connection: keep-alive
为什么如果请求是HEAD
,nginx 会省略Content-Length
标头?php 脚本非常简单,不会以HEAD
任何特殊方式响应。
我可以在 nginx 中打开任何选项,以便它也发送Content-Length
forHEAD
吗?
相关nginx信息:
nginx version: nginx/1.2.8
built by gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.2.8 --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre --conf-path=/etc/nginx/nginx.conf --add-module=../headers-more-nginx-module-0.19rc1
配置:
user www-user;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10M;
sendfile on;
keepalive_timeout 65;
more_clear_headers "Server";
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;
server {
server_name test.com;
root /www;
index index.php index.html index.htm;
listen 80 default_server;
rewrite ^/(.*)/$ /$1 permanent; #remove trailing slash
#charset koi8-r;
#access_log logs/host.access.log main;
include general/*.conf;
#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 html;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
我有一个在 Ubuntu Desktop 12.04 上完美运行的 PHP-FPM 和 nginx 设置。Web 服务器的文件从名为 的目录提供,该目录/www
设置为root
服务器的目录。
最初,/www
作为 VMware 共享文件夹安装(因为 Ubuntu 桌面作为来宾操作系统运行)。但是,由于共享文件夹的性能问题(延迟 2 秒!),我正在测试 samba 共享。
我的 Windows 7 主机上有一个名为webfiles
shared 的文件夹作为网络共享。我可以/www
通过将它作为 cifs 安装在我的中来自动安装它fstab
:
//192.168.1.7/webfiles /www cifs credentials=/home/user/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0
/www
启动时挂载良好,我可以在 Ubuntu 中创建和删除文件。Nginx 也能够毫无问题地从中提供静态文件。
问题是,一旦我希望它通过 PHP-FPM 为 PHP 文件提供服务器,我就会开始File not found.
出错。尽管事实上设置工作得很好,唯一改变的是/www
,我现在有一个 samba 共享,而不是挂载在 的共享文件夹。
我对 samba 不是很熟悉,但这可能是什么原因造成的?
我正在运行带有 nginx 1.2.6 的 Ubuntu Desktop 12.04。PHP 是 PHP-FPM 5.4.9。
这是我的相关部分nginx.conf
:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name testapp.com;
root /www/app/www/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80 default_server;
root /www
index index.html index.php;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
相关位来自php-fpm.conf
:
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = /www
在我的主机文件中,我重定向了2 个域:testapp.com
和.test.com
127.0.0.1
我的网页文件都存储在/www
.
从上面的设置来看,如果我访问test.com/phpinfo.php
and test.com/app/www
,一切都会按预期进行,并且我会从 PHP 获得输出。
但是,如果我访问testapp.com
,我会得到可怕的No input file specified.
错误。
所以,在这一点上,我拉出日志文件看看:
2012/12/19 16:00:53 [error] 12183#0: *17 FastCGI sent in stderr: "Unable to open primary script: /www/app/www/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: testapp.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "testapp.com"
这让我很困惑,因为我检查了一遍又一遍,/www/app/www/index.php
确实存在!这也通过有效的事实得到验证,test.com/app/www/index.php
这意味着文件存在并且权限正确。
testapp.com
为什么会发生这种情况?仅v-host出现故障的根本原因是什么?
只是对我的调查的更新:
我已经评论出来并chroot
缩小问题范围chdir
php-fpm.conf
如果我删除location ~ \.php$
块testapp.com
,那么 nginx 将向我发送一个包含 PHP 代码的 bin 文件。这意味着在 nginx 方面,一切都很好。
问题是在将文件传递给 PHP-FPM 时一定有什么东西破坏了文件路径。
default_server
话虽如此, v-host 可以正常工作是很奇怪的,因为它的根是/www
,而 v-host 却不起作用,testapp.com
因为根是/www/app/www
.
我看到一个奇怪的问题,如果我在启动它时php.ini
没有明确地将它传递给它,我就不会被使用。php-fpm
这是我正在使用的新贵脚本:
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [016]
pre-start script
mkdir -p /run/php
end script
expect fork
respawn
exec /usr/local/php/sbin/php-fpm --fpm-config /etc/php/php-fpm.conf
如果 PHP 以上述方式启动,php.ini
则永远不会使用 my,即使它位于Configuration File (php.ini) Path
.
这是来自的相关部分phpinfo()
:
Configuration File (php.ini) Path /etc/php/
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
php-fpm
如果我修改 upstart 脚本的最后一行以 php.ini
明确指向:
exec /usr/local/php/sbin/php-fpm --fpm-config /etc/php/php-fpm.conf -c /etc/php/php.ini
然后我们看到php.ini
加载了:
Configuration File (php.ini) Path /etc/php/
Loaded Configuration File /etc/php/php.ini
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
为什么会这样?这是 php-fpm 中的一个怪癖吗?
次要更新:这似乎也是使用apt-get
.
我通过运行以下命令在 Ubuntu Server 12.04 虚拟机中进行了测试安装:
sudo apt-get install nginx php5-fpm
安装后启动了 PHP-FPM 和 nginx,一切似乎都很好。然后我在 nginx 的配置中取消注释 php 的设置并放置一个测试phpinfo()
文件来检查 PHP 的设置。
相关位是:
Configuration File (php.ini) Path /etc/php5/fpm
Loaded Configuration File (none)
Scan this dir for additional .ini files /etc/php5/fpm/conf.d
Additional .ini files parsed /etc/php5/fpm/conf.d/10-pdo.ini
我注意到也没有php.ini
加载。但是,如果我转到/etc/php5/fpm
,我可以看到 aphp.ini
存在。我还检查了 PHP-FPM 的启动脚本,并且-c
没有使用参数将 ini 文件链接到 PHP。对于希望 php.ini 由 PHP-FPM 自动加载的人来说,这可能会造成混淆。
我正在运行 Ubuntu Server 12.04,并且更喜欢自己编译 PHP 而不是使用apt-get
. PHP 作为 PHP-FPM 运行。
编译扩展时,我可以使用诸如此类的方式将其设置为编译为共享扩展--with-bcmath=shared
。
将扩展编译为共享有什么好处吗?
我还注意到扩展被编译到一个非常复杂的文件夹中。在我的系统上(我的 php 前缀是/usr/local/php-5.4.9
),扩展名以/usr/local/php-5.4.9/lib/php/extensions/no-debug-non-zts-20100525
.
是否有一种全局方式来设置文件夹以便所有共享扩展都将在那里编译?我知道我可以做类似的事情,--with-foobar=shared,/usr/local/foobar/
但必须为每个共享扩展设置扩展文件夹效率低下且容易出错。
我目前正在测试 nginx 并设置了一些虚拟主机,方法是将每个虚拟主机的配置放在一个名为sites-enabled
.
然后我要求 nginx 使用以下命令加载所有这些配置文件:
include C:/nginx/sites-enabled/*.conf;
这是我当前的配置:
http {
server_names_hash_bucket_size 64;
include mime.types;
include C:/nginx/sites-enabled/*.conf;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
root C:/www-root;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm index.php;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server{
server_name localhost;
}
}
这是虚拟主机的配置之一:
server {
server_name testsubdomain.testdomain.com
root C:/www-root/testsubdomain.testdomain.com;
}
问题是对于 testsubdomain.testdomain.com,我无法让 php 脚本运行,除非我为它定义了一个带有 fastcgi 参数的位置块。
我想做的是能够为此服务器上的所有托管站点启用 PHP(无需添加带有 fastcgi 参数的 PHP 位置块)以实现可维护性。这样一来,如果我需要更改 PHP 的任何 fastcgi 值,我只需在 1 个位置更改它。
这对 nginx 来说是可能的吗?如果是这样,如何做到这一点?