域名 a.cn 俩 子域名 www.a.cn -> PC 站 ,m.a.cn -> 移动站
不带 www 自动跳转到 www
Nginx 配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name a.cn www.a.cn;
return 301 https://www.a.cn$request_uri;
}
server {
listen 80;
server_name m.a.cn;
return 301 https://m.a.cn;
}
# HTTPS server
#
server {
listen 443 ssl;
server_name www.a.cn;
ssl_certificate C://nginx//ssl//www.a.cn.crt;
ssl_certificate_key C://nginx//ssl//www.a.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_http_version 1.1;
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;
proxy_pass http://127.0.0.1:5000;
}
}
server {
listen 443 ssl;
server_name m.a.cn;
ssl_certificate C://nginx//ssl//m.a.cn.crt;
ssl_certificate_key C://nginx//ssl//m.a.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_http_version 1.1;
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;
proxy_pass http://127.0.0.1:5000;
}
}
}
Flask 配置 域名
Flask SERVER_NAME = 'a.cn'
a.cn, m.a.cn 可以访问 ,www.a.cn 无法访问
Flask 配置:app.url_map.default_subdomain = 'www'
正常访问 但 m.a.cn 也是返回的 www.a.cn 即 PC 页面
蓝图配置 域名
删除 app.url_map.default_subdomain = 'www'
, 蓝图 增加 subdomain='www'
正常
唯一的问题 url_for()
获取的绝对路径域名 不带www
这个配置过程有点凌乱,有没有比较便捷的配置方法,目前设置基本符合条件但就是一个问题 , url_for
获取到的域名怎么带 www
万分感谢!