对于centos(linux)下使用nginx的总结

2019-03-20  本文已影响0人  QRFF
 location / {
        deny   123.9.51.42;
        allow  232,123,123,2;
    }
=号代表精确匹配
location =/img{
        allow all;
    }
正则匹配
location ~\.php$ {
        deny all;
    }
  1. 配置虚拟主机
    虚拟主机就是可以在服务器上配置多个域名;一般通过设置端口号来实现;
server{
        listen 8001;
        server_name localhost;
        root /usr/share/nginx/html/html8001;
        index index.html;
}

  1. 反向代理
server{
        listen 80;
        server_name test12.com;
        location / {
               proxy_pass http://test34.com;
        }
}
  1. nginx判断移动和pc
server{
        listen 80;
        server_name test.com;
        location / {
         root /usr/share/nginx/pc;
         if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
            root /usr/share/nginx/mobile;
         }
         index index.html;
        }
}
  1. nginx 开启gzip压缩
http {
   .....
    gzip on;
    gzip_types text/plain application/javascript text/css;
   .....
}
  1. nginx 配置跨域
location /apis { #添加访问目录为/apis的代理配置
            rewrite  ^/apis/(.*)$ /$1 break;
            proxy_pass   http://localhost:82;
 }
上一篇下一篇

猜你喜欢

热点阅读