zoukankan      html  css  js  c++  java
  • Nginx 代理配置

    nginx 正向http代理配置 需要用户名和密码认证

    生成密码文件:

    linux需要安装:
     #yum -y install httpd-tools
    生成密码文件:
    #htpasswd -c /usr/local/nginx/conf/pwd/passwd 用户名 输入密码 重新输入密码

    server配置:

    在conf的目录下创建hosts文件夹并在nginx.conf最后插入 include hosts/*.conf;

    在hosts中创建文件myproxy.conf

    server {
            access_log /usr/local/nginx/logs/access.log;#日志目录
            listen 39001;#监听端口
            location / {
                    resolver 8.8.8.8;#DNS地址
                    proxy_pass $scheme://$http_host$request_uri;
                    auth_basic "Please input password";#提示
                    auth_basic_user_file /usr/local/nginx/conf/pwd/passwd;#用户密码加密文件
                    proxy_buffers   256 4k;#缓存大小
                    proxy_max_temp_file_size 0k;
            }
    }

    命令:

    nginx -s reload|reopen|stop|quit  #重新加载配置|重启|停止|退出nginx
    nginx -t   #测试配置是否有语法错误

    文件服务器配置:

    进行简单配置
             在安装目录的conf文件夹下的nginx.conf中配置:
                      location ^~ /svn/ {    //表示含有svn/关键字就会进入以下规则
                         root /data/;
                         autoindex on;
                     }
             以上表示:http://[ip]/svn/ 实际访问路径为:/data/svn/;autoindex on表示打开目录浏览功能。当然nginx
          的规则配置还有很多,可以自行百度。
             


    注意:location = / (精确匹配)与 location  /(模糊匹配)。后者表示请求地址只要含有/,就会给实际访问路径加上其规则里面配置的路径。比如:
             配置文件:
                       location  / {
                              root html;
                              index  index.html index.htm;
                           }
                              
                       location ^~ /svn/ { 
                              root /data/;
                              autoindex on;
                     }
             那么请求“http://[ip]/svn/”则会先被“location  /”匹配,实际访问路径变成:/usr/local/nginx/html,然      后继续匹配发现满足svn关键字,故又加上/data/svn/,因此实际访问路径是/usr/local/nginx/html/data/svn/。
             另: location = / {
                root   html;
                index  index.html index.htm;
            }中的“root html”,表示当前安装目录下的html,“root /html”否则表示服务器根目录下的html。

    为梦想不止不休!
  • 相关阅读:
    不应滥用named let
    PAT甲级——A1106 Lowest Price in Supply Chain
    PAT甲级——A1105 Spiral Matrix【25】
    PAT甲级——A1104 Sum of Number Segments
    PAT甲级——A1103 Integer Factorization
    PAT甲级——A1102 Invert a Binary Tree
    PAT甲级——A1101 Quick Sort
    PAT甲级——A1100 Mars Numbers
    PAT甲级——A1099 Build A Binary Search Tree
    PAT甲级——A1098 Insertion or Heap Sort
  • 原文地址:https://www.cnblogs.com/virtulreal/p/9546570.html
Copyright © 2011-2022 走看看