zoukankan      html  css  js  c++  java
  • Nginx Rewrite域名及资源重定向!(重点)

    第一步:搭建Nginx服务

    第二步:修改主配置文件

    [root@ns2 ~]# vim /usr/local/nginx/conf/nginx.conf
    user  nginx nginx;
    worker_processes  2;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    error_log  logs/error.log  info;
    worker_cpu_affinity 00000001 00000010;
    pid        logs/nginx.pid;
    
    
    events {
       use epoll;
        worker_connections  10240;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  logs/access.log  main;
    
        sendfile        on;
    
        keepalive_timeout  65;
    
       server {
            listen       80;
            server_name  www.source.com;

    charset utf-8;

    
    

    access_log logs/source.com.access.log main;

    
    

    location / {
            root html;
            index index.html index.htm;
          if ($http_user_agent ~ MSIE) {
               rewrite ^(.*)$ /msie/$1 break;
             }
         }
     location ~* .(js|css)$ {
         expires 1h;
    }

    
    


    location ~* .(jpg|gif|png|swf)$ {
          #*.amber.com amber.com相当于公司域名
         expires 1d;
         root html;
         valid_referers none blocked *.source.com source.com;
       if ($invalid_referer) {
            rewrite ^/ http://www.source.com/error.txt;
        }
    }

    
    

          error_page 500 502 503 504 /50x.html;
       location = /50x.html {
        root html;
    }
    }

    
    

    }

     

    [root@ns2 ~]#  cd /usr/local/nginx/html

    [root@ns2 html]#mkdir msie

    [root@ns2  html]#cd msie

    [root@ns2 msie]#vim a.html

    <h1>11111111</h1>

    [root@ns2 msie]# ls
    a.html

    第三步:修改真机hosts文件(此处用于防盗链)

    192.168.200.100 www.source.com
    192.168.200.105 www.sttal.com

  • 相关阅读:
    51nod 1113 矩阵快速幂 如题目
    poj Raising Modulo Numbers 快速幂模板(取膜)
    bzoj 1503: [NOI2004]郁闷的出纳员 平衡树
    codevs 1063 合并果子 优先队列相关
    bzoj 3224: Tyvj 1728 普通平衡树 Treap模版
    快排模板
    hdu 4353 统计点在三角形内的个数
    hdu 3264 圆的交+二分
    hdu 3685 多边形重心+凸包
    hdu 3992 AC自动机上的高斯消元求期望
  • 原文地址:https://www.cnblogs.com/CMX_Shmily/p/11519685.html
Copyright © 2011-2022 走看看