Redirect nginx在本地主机上将http重定向到https
我正在本地测试nginx作为反向代理 我想将通配符子域http重定向到https 子域在应用程序中以编程方式处理Redirect nginx在本地主机上将http重定向到https,redirect,nginx,https,localhost,Redirect,Nginx,Https,Localhost,我正在本地测试nginx作为反向代理 我想将通配符子域http重定向到https 子域在应用程序中以编程方式处理 server { listen 80; server_name ~^(.*)\.localhost$; return 301 https://$server_name$request_uri; } server { listen 443 ssl; gzip on
server {
listen 80;
server_name ~^(.*)\.localhost$;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
server_name ~^(.*)\.localhost$;
# SSL Certs
ssl_certificate /path/to/server.crt;
ssl_certificate_key /path/to/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://localhost:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
直接从chrome访问https效果很好
访问http实际上没有任何作用,甚至连页面刷新都没有您是否尝试过使用
$host
而不是$server\u name
。当server\u name
指令是正则表达式时,我不确定将$server\u name
设置为什么值。请详细说明我应该在上面的配置中更改什么?