lumen 部署在nginx 子目录下配置 IDC增强版 

今天吃完饭回来就在想上午的那个方案虽然可行,但是有个弊端。

就是每上一个新版本,除了上传新版本文件夹之外 还得编辑下 nginx vhost 配置,新增一个虚拟主机。

说麻烦虽然不麻烦 不过也挺烦人的。没有做到自适应,需要人工干预。

所以又折腾了一下。

配置如下:

server {
listen 80;
server_name haha.17ping.cn;
root /data/www/sdkHoster;

location / {
index index.php index.htm index.html;
autoindex on;
}

location ~ /([\w\d_]+)/([\w/]*)$ {
index index.php index.htm index.html;
try_files $uri $uri/ /$1/public/index.php?$query_string;
#return 500 $1;
}

# location /sdk1_0 {
# root /data/www/sdkHoster;
# index index.php index.htm index.html;
# try_files $uri $uri/ /sdk1_0/public/index.php?$query_string;
# }

# location /sdk1_1 {
# root /data/www/sdkHoster;
# index index.php index.htm index.html;
# try_files $uri $uri/ /sdk1_1/public/index.php?$query_string;
# }

location ~ \.php$ {
set $newurl $request_uri;
if ($newurl ~ ^/sdk([\d_]+)(.*)$) {
set $newurl $2;
}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
fastcgi_param REQUEST_URI $newurl;
}

location ~ \.(css|js|swf|php|htm|html)$ {
add_header Cache-Control no-store;
}

location ~ /\.ht {
deny all;
}
}


保存,重载配置。

手动复制了一份 sdk1_2 目录,重命名为sdk1_2.
访问 http://haha.17ping.cn/sdk1_2/ 成功,美滋滋。

注:本文撰写实践时参考了一下文章:
https://serverfault.com/questions/826663/nginx-location-regex-variable-not-working-with-try-file
https://stackoverflow.com/questions/33890599/nginx-match-location-with-regex
https://superuser.com/questions/330194/how-to-i-get-variables-from-location-in-nginx
http://nginx.org/en/docs/http/ngx_http_ ... l#location
http://nginx.org/en/docs/http/ngx_http_ ... log_format
http://nginx.org/en/docs/http/ngx_http_ ... tml#return
https://regex101.com/
[ ] ( 10694 次浏览 ) 永久链接 ( 2.9 / 1946 )

<< <上一页 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 下一页> >>