我想重写特定的位置https这里:
server { listen 80; server_name mysite.com www.mysite.com; root /var/www/$server_name/public; #error_log /error.logg debug; error_page 403 /403.html; location = /403.html { allow all; } location / { #allow xxx.xxx.xxx; #deny all; index index.html index.htm index.php; try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /register { rewrite ^ https://$http_host$request_uri?$args permanent; } location /login { rewrite ^ https://$http_host$request_uri?$args permanent; } }
/register和/login不是我需要写的唯一的地方,那么我将如何处理多个位置,而不是重复每个地方我想要重写到https的位置块?
您可以使用正则expression式位置匹配,如下所示:
location ~ ^/(login|register) { rewrite ^ https://$http_host$request_uri?$args permanent; }