[TOC] ``` server { listen 80; server_name noval.wmlzy.cn; root /www/noval_admin/public; index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last; rewrite ^(.*)$ /index.php?s=$1 last; break; } location ~ \.php(.*)$ { root /www/noval_admin/public; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #nginx支持tp fastcgi_param PATH_INFO $1; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } } ``` * 添加 ssl 证书 以下代码添加到 index index.php index.html index.htm; 下面 具体配置 可申请证书的时候查看 ~~~ ssl_certificate_key /usr/local/nginx/cert/zy.wmlzy.cn.key; ssl_certificate /usr/local/nginx/cert/zy.wmlzy.cn_bundle.crt; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; ~~~ * 默认跳转到 https 在配置最下面加上 ~~~ server { listen 80; server_name zy.wmlzy.cn; rewrite ^(.*)$ https://$host$1 permanent; } ~~~ ![](https://img.kancloud.cn/9f/68/9f680a8acb1c9320a9f735d7d775103a_507x229.png) ``` server { listen 80; listen 443 ssl http2; server_name ~^([a-zA-Z0-9]+)-api-cmv2\.test\.pjpfljcw\.com$; set $userName $1; include all_ssl_params; index index.html index.htm index.php index.shtml; root /home/$userName/www/api-cmv2/; error_log /data/wwwlogs/all-api-cmv2.error_nginx.log error; access_log /data/wwwlogs/all-api-cmv2.access_nginx.log ; index index.php; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; if (!-f $request_filename){ # proxy_pass http://127.0.0.1:18787; proxy_pass http://unix:/tmp/$userName-api-cmv2.sock; } } } ``` ### 模糊匹配 ``` server { listen 80; listen 443 ssl http2; server_name ~^([a-zA-Z0-9]+)-api-cmv2\.test\.pjpfljcw\.com$; set $userName $1; include all_ssl_params; index index.html index.htm index.php index.shtml; root /home/$userName/www/api-cmv2/; error_log /data/wwwlogs/all-api-cmv2.error_nginx.log error; access_log /data/wwwlogs/all-api-cmv2.access_nginx.log ; index index.php; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; if (!-f $request_filename){ # proxy_pass http://127.0.0.1:18787; proxy_pass http://unix:/tmp/$userName-api-cmv2.sock; } } } ``` ``` server { listen 80; listen 443 ssl http2; server_name ~^([a-zA-Z0-9]+)-((h5|admin)-[a-zA-Z0-9]+)\.test\.pjpfljcw\.com$; set $userName $1; set $projectHome $2; include all_ssl_params; index index.html index.htm index.php index.shtml; root /home/$userName/www/$projectHome; error_log /data/wwwlogs/all-h5.error_nginx.log error; access_log /data/wwwlogs/all-h5.access_nginx.log ; location / { try_files $uri $uri/ /index.html; } } ``` server { listen 80; listen 443 ssl http2; server_name ~^([a-zA-Z0-9]+)-api-hf\.test\.pjpfljcw\.com$; set $userName $1; include all_ssl_params; index index.html index.htm index.php index.shtml; root /home/$userName/www/api-hf/; error_log /data/wwwlogs/wumengliang-api-hf.error_nginx.log error; access_log /data/wwwlogs/wumengliang-api-hf.access_nginx.log ; index index.php; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; if (!-f $request_filename){ # proxy_pass http://127.0.0.1:18787; proxy_pass http://unix:/home/wumengliang/www/api-hf/runtime/http.sock; } } } ``` ```