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
}
}
}