經過一系列的審核,耗時近一個月的網(wǎng)站備案終于通過刨啸,便迫不及待地進行了域名解析堡赔。需要分別對PC和手機進行配置,具體如下设联。
一善已、需求
客戶端 | 域名 | 描述 | 訪問目錄 |
---|---|---|---|
PC端 | www.harriszhang.cn | 用于PC端訪問 | /var/www/space/space/index.html |
手機端 | m.harriszhang.cn | 用于移動端訪問 | /var/www/space/spaceMobile/index.html |
當在PC端訪問www.harriszhang.cn
或m.harriszhang.cn
時,跳轉到www.harriszhang.cn
离例。
當在移動端訪問www.harriszhang.cn
或m.harriszhang.cn
時换团,跳轉到m.harriszhang.cn
二、Nginx配置
2.1 PC訪問配置
修改前:
server {
listen 80;
server_name localhost;
location / {
root /var/www/space/space;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
...
}
修改后:
server {
listen 80;
server_name www.harriszhang.cn;
if ($http_host !~ "www.harriszhang.cn$") {
rewrite ^(.*) http://www.harriszhang.cn$1 permanent;
}
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
rewrite ^(.*) http://m.harriszhang.cn$1 permanent;
}
location / {
root /var/www/space/space;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
...
}
2.2 移動端訪問配置
修改前:
server {
listen 80;
server_name localhost;
location / {
root /var/www/space/spaceMobile;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
...
}
修改后:
server {
listen 80;
server_name m.harriszhang.cn;
if ($http_user_agent !~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
rewrite ^(.*) http://www.harriszhang.cn$1 permanent;
}
location / {
root /var/www/space/spaceMobile;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
...
}
三宫蛆、重啟Nginx
通過nginx -s reload
命令重新啟動 Nginx艘包,即可看到設置已經生效。