nginx目錄結構
nginx
├── conf // 配置文件
│ └── annotation // 自定義註解
├── html // html頁面
│ └── pc // PC端
│ └── index.html //首頁
│ └── mobile // 移動端
│ └── index.html //首頁
├── sbin // nginx 命令
│ └── nginx
訪問不同頁面
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /{
#PC端根路徑
root html/pc;
#通過user-agent判斷來源是移動端還是PC端
if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") {
#移動端根路徑
root html/mobile;
}
#
index index.html;
}
訪問不同域名
server {
listen 80;
server_name xxx.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") { #判斷是否爲移動設備訪問
rewrite ^/(.*)$ http://m.xxx.com$uri redirect; # 跳轉到m.xxx.com
}
}
}