您的位置:首页 > 编程语言 > PHP开发

PHP代码发布-基于软链

2018-03-03 00:00 218 查看
摘要: 如果用的发布系统是基于软链更新代码的,比如发布新版本由 /data/release/version1 切换到 /data/release/version2。

那么nginx好像有缓存,永远不会生效新的代码。

使用软链接实现

nginx 新版本 软链 变化
https://www.jianshu.com/p/652789985230

把 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
改成 fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

这个软链就可以自动更新了,index.php 拿到的 DIR 是最新的。

作者:龙权
链接:https://www.jianshu.com/p/652789985230
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关资料

nginx wiki
https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/

The minimum configuration to get your application running under Nginx is:

Secure Symfony 3.x, 2.x

server {
server_name domain.tld www.domain.tld;
root /var/www/project/web;

location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 # for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 # for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path # Remove the internal directive to allow URIs like this
internal;
}

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/project_error.log;
a
7fe0
ccess_log /var/log/nginx/project_access.log;
}

Depending on your PHP-FPM config, the fastcgi_pass can also be fastcgi_pass 127.0.0.1:9000.

This executes only app.php, app_dev.php and config.php in the web directory. All other files ending in ".php" will be denied.

If you have other PHP files in your web directory that need to be executed, be sure to include them in the location block above.

After you deploy to production, make sure that you cannot access the app_dev.php or config.php scripts (i.e. http://example.com/app_dev.php and http://example.com/config.php). If you can access these, be sure to remove the DEV section from the above configuration.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Nginx