有的时候想快速部署一个测试demo,还要新建一个nginx配置文件,再做一个域名解析,麻烦得很。突发奇想,将一个二级域名泛解析,然后写一份通用的nginx配置文件就可以免去烦恼了。
server
{
listen 80;
listen 443 ssl http2;
server_name ~(.+)\.test\.example\.com$;
index index.php index.html index.htm;
set $path $1;
root /path/to/www/testwebsite/$path;
ssl on;
ssl_certificate /path/to/your.cer; # 需要野卡ssl
ssl_certificate_key /path/to/your.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
location ~ [^/]\.php(/|$)
{
alias /path/to/www/testwebsite/$path;
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log off;
}
如果把一个项目clone到了/path/to/www/testwebsite/x1,直接访问x1.test.example.com就可以了。
本文由 hunsh 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Aug 26, 2019 at 09:12 pm