nginx配置-通用的测试站点

in Nginx with 0 comment

有的时候想快速部署一个测试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就可以了。

Responses