我试图强制仅将桌面(非移动)流量重定向到 HTTPS。我使用 Nginx,然后为这个特定的域反向代理到 Apache。这是我当前的配置:
server {
server_name example.com www.example.com;
location / {
proxy_pass http://EXAMPLE_IP:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
使用这个 Nginx 代码:
如何添加逻辑来进行用户代理检测并进行正确的重定向?
我确实发现了这段代码来检测非移动流量 - https://gist.github.com/perusio/1326701