根域名做301跳轉(zhuǎn)的方法:
1.在域名服務(wù)商,將根域名解析到目標(biāo)服務(wù)器ip地址。
2.在nginx新建xxx.com.conf的vhost文件,內(nèi)容如下:
vi xxx.com.conf
server {
listen 80;
server_name xxx.com;
rewrite ^(.*)$ http://www.xxx.com$1 permanent;
}
server {
listen 443 ssl http2;
server_name xxx.com;
rewrite ^(.*)$ https://www.xxx.com$1 permanent;
ssl_certificate certs/Nginx/1_www.xxx.com_bundle.crt;
ssl_certificate_key certs/Nginx/2_www.xxx.com.key;#由于這兩個命令的默認(rèn)值已經(jīng)好幾次發(fā)生了改變,因此不建議顯性定義,除非有需要額外定義的值
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
charset utf-8;
access_log logs/localhost.access.log main;
error_log logs/localhost.error.log warn;
root html;
index index.php index.html index.htm;
location / {
……
}
}
3.這樣在瀏覽器訪問xxx.com,就會自動跳轉(zhuǎn)到www.xxx.com了。