Nginx和/或php5-fpm记住符号链接的根目录 [英] Nginx and/or php5-fpm remembers symlinked root directory
问题描述
我的nginx网站根指向一个符号链接.如果我更改了符号链接(又名部署了网站的新版本),则旧版本的php脚本会一直显示. 闻起来像是缓存或错误.
My nginx site root points to a symlink. If I alter the symlink (aka deploy a new version of the website) the old version of the php script keeps showing up. That smells like cache, or a bug.
首先,看起来好像Nginx正在缓存符号链接的dir,但是重新加载/重新启动/杀死并启动nginx并不能解决它,所以我重新启动了php5-fpm-这解决了我的问题.
First it looked like Nginx was caching the symlinked dir, but reloading/restarting/killing and starting nginx didn't fix it, so I restarted php5-fpm - this fix my issue.
但是我不想在部署后重新启动nginx和/或php5-fpm-我想知道为什么会有这样的缓存(或错误),以及为什么它不能正常工作.
But I dont want to restart nginx and/or php5-fpm after a deploy - I want to know why there is such a cache (or bug), and why it didn't work properly.
使用完整信息:
- 操作系统:Ubuntu 13.10(GNU/Linux 3.8.0-19-通用x86_64)
- Nginx:通过ppa:nginx/stable
- PHP:通过ppa:ondrej/php5(php5-fpm)
Nginx站点配置:
Nginx site config:
root /home/rob/sandbox/deploy/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
Nginx服务器配置(部分为默认设置):
Nginx server config (partly, rest is default):
http {
sendfile off;
upstream php {
server unix:/var/run/php5-fpm.sock;
}
}
/home/rob/sandbox的树:
Tree for /home/rob/sandbox:
├── deploy -> web2
├── web1
│ └── public
│ └── index.php (echo ONE)
└── web2
└── public
└── index.php (echo TWO)
- 请求:
http://localhost/index.php
- 预期的响应:两个
- 实际回答:一个</li>
- request:
http://localhost/index.php
- expected response: TWO
- actual response: ONE
realpath_cache_get()
[/home/rob/sandbox/deploy/public/index.php] => Array ( [key] => 1.4538996210143E+19 [is_dir] => [realpath] => /home/rob/sandbox/web2/public/index.php [expires] => 1383730041 )
所以这意味着
deploy/public/index.php
已正确链接到web2/public/index.php
,对吗? 好吧,即使realpath_cache列表中的路径正确,重做仍然是ONE.So this means
deploy/public/index.php
is properly linked toweb2/public/index.php
, right? Well, even with the correct paths in the realpath_cache list, the respone still is ONE.rm deploy
和ln -s web2 deploy
Nginx重新启动后,没有任何效果. 此后重新启动php5-fpm可获得预期的响应"TWO".After
rm deploy
andln -s web2 deploy
Nginx was restarted, no effect. Restarting php5-fpm after this gives the expected response of 'TWO'.很高兴知道,除了index.php文件之外,我还对.css和.js文件进行了一些测试. 在从web1和web2删除并重新创建符号链接之后,nginx将以文件的正确内容进行响应.
It's good to know that beside the index.php files, I did some test with .css and .js files. After removing and recreating the symlink from/to web1 and web2, nginx will respond with the correct contents of the files.
我想念什么,我没看到什么?
What did I miss, what am I not seeing?
推荐答案
一旦我将realpath_cache_ttl更改为"2"(应该修复它),仍然显示了错误的内容.
Once I altered the realpath_cache_ttl to '2' (That should fix it) the incorrect content was still showing.
在对php-fpm的加载的mod进行了一些挖掘之后,我发现opcache已启动并正在运行.禁用该选项将在ttl结束时清除缓存的真实路径.
After some digging in the loaded mods for php-fpm, I discovered that opcache was up and running. Disabling that will clear the cached realpath's when the ttl is over.
我不想将realpath缓存ttl降低很多,所以我会重新加载php-fpm,因为它很优美. 我希望这个主题和我的回答会对其他人有所帮助;)
I don't wanna lower the realpath cache ttl to much,so I will settle in with a reload of php-fpm, since it is graceful. I hope this thread and my answers will help others ;)
这篇关于Nginx和/或php5-fpm记住符号链接的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- request: