Nginx 配置区分手机和PC网页

手机的配置

server {
    listen            80;
    server_name       m.in83.com;
    access_log        /var/www/nginx/m.in83.com.log;
    index             index.htm index.html;
    root              /var/www/in83/m/;
    location  =/ {
            index             index.htm index.html;
            root              /var/www/in83/m/;
    }
    location  / {
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
            set $mobile_request '0';
            if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
                set $mobile_request '1';
            }
            if ($mobile_request != '1') {
                rewrite ^.+ http://www.in83.com$uri;
            }
            if (!-f $request_filename) {
                proxy_pass        http://115.159.142.246:2020;
                break;
            }
    }
}

PC的配置

server {
    listen            80;
    server_name       in83.com www.in83.com;
    access_log        /var/www/nginx/www.in83.com.log;
    index             index.htm index.html;
    root              /var/www/in83/www/;
    location  =/ {
            index             index.htm index.html;
            root              /var/www/in83/www/;
    }
    location  / {

            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 ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
                set $mobile_request '1';
            }
            if ($mobile_request = '1') {
                rewrite ^.+ http://m.in83.com$uri;
            }
            if (!-f $request_filename) {
                proxy_pass        http://115.159.142.246:2020;
                break;
            }
    }
}

常规配置

server {
    listen            80;
    server_name       cis.in83.com;
    access_log        /var/www/nginx/cis.in83.com.log;
    index             index.htm index.html;
    root              /var/www/in83/cis/;
    location  / {
            proxy_pass        http://115.159.142.246:2020;
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

静态资源配置

server {
    listen            80;
    server_name       s.in83.com;
    access_log        /var/www/nginx/s.in83.com.log;
    index             index.htm index.html;
    root              /var/www/in83/s/;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,532评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • 转自:http://blog.csdn.net/xiao__gui/article/details/4668086...
    光光李阅读 2,924评论 0 2
  • 前日收到朋友父亲的微信消息,说不要那么急于求成的做决定,作贱了自己,要认真思考。很长的一段话,我没记全。 这一次住...
    苏向晚阅读 536评论 4 1
  • 父亲节。我在北京,和我爸隔了八百多公里的距离。我在我曾经最想抵达的城市的盛夏里,举着太阳伞躲避着白日里炽...
    吟游至下半世纪阅读 1,688评论 2 3