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。

原文地址:https://www.cnblogs.com/virtulreal/p/9546570.html

时间: 2024-08-28 02:29:31

Nginx 代理配置的相关文章

【vue2.0】去掉前面#,window下nginx代理配置

1.定义路由,设置路由配置 const routes = [ { path: '/login', component: require('./components/login/index.vue') }, { // = = = => /home path: '/home', component: Home }, { path: '/', redirect: '/home' }, { path: '*/*', redirect: '/home' }]; const router = new Vue

nginx代理配置 配置中的静态资源配置,root 和 alias的区别。启动注意事项

这篇主要内容是:nginx代理配置 配置中的静态资源配置,root 和 alias的区别.启动注意事项! 为什么会在window上配置了nginx呢?最近我们的项目是静态资源单独放在一个工程里面,后端请求的静态资源和请求接口想要请求类似  127.0.0.1/web 就可以同时能显示后台接口返回的数据和js,jquery这种静态资源,就必要配置一个代理服务器.代理静态资源和web请求的服务器. 之前是使用Xampp这种软件中的apache作为静态资源服务器,感觉有点占用空间,配置还比nginx配

【Linux】添加Nginx代理配置只允许内部IP访问

location / { index index.jsp; proxy_next_upstream http_500 http_502 http_503 http_504 error timeout invalid_header; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; deny 192.168.1.1;

nginx代理配置

server {     listen       80;     server_name  api.colortrip.cn;     client_max_body_size 10m;     access_log /dev/null;     #error_log /dev/null;     error_log  /home/nginxlog/errorlog/error.log;     location / {         return 403;     }     locati

nginx配置访问控制、rewrite应用、nginx代理

一.访问控制 限制只让某个ip访问: allow 192.168.1.100; deny all; 限制只有本地地址可以访问,白名单: allow 127.0.0.1; deny all; 拒绝本地访问,黑名单: deny 127.0.0.1; allow all; deny all 直接拒绝所有,下面的allow就不生效了. [[email protected] vhosts]# vi default.conf server {     listen 80 default_server;   

外网nginx 代理(vpn)到 内网 配置,实现外网的访问内网 (亲测可以实现);

外网安装 vpn服务,内网接入vpn: 外网通过nginx 代理到内网(nginx): #外网nginx代理 server { listen 80; server_name *.test.xxxx.com; charset utf-8; location / { #root /var/www; #index index.jsp; proxy_pass http://10.0.0.2:80/; include proxy.conf; } } # 代理配置文件 proxy.conf proxy_re

Nginx主配置参数详解,Nginx配置网站

1.Niginx主配置文件参数详解 a.Linux中安装nginx.博文地址为:http://www.cnblogs.com/cindy-cindy/p/6847499.html b.当Nginx安装完毕后,会有相应的安装目录,安装目录里的nginx.confg为nginx的主配置文件,nginx主配置文件分为4部分,main(全局配置).server(主机配置).upstream(负载均衡服务器设置)以及location(URL匹配特定位置的设置),这四者的关系是:server继承main,l

nginx代理配置文件模板示例

# 4核8g机器的nginx代理配置 # vim /usr/local/nginx/conf/nginx.conf user  nginx; worker_processes  8; worker_rlimit_nofile 102400; error_log  /data0/log/nginx/error.log  notice; pid        /data0/log/nginx/nginx.pid; events {     use epoll;     worker_connecti

Nginx实战配置详解

当单台服务器的负载达到一定程度时,服务器资源就无法满足用户的需求,此时可以通过多种方法来处理.比如说通过DNS解析多台服务器,或者是通过四层根据内容请求进行分发(如LVS),或是通过七层负载技术(nginx.haproxy)等方式来实现.Nginx的反向代理负载均衡能够更好的支持虚拟主机,可配置性强,可以根据服务器的硬件配置按比重进行轮询.权重负载,也可以根据IP哈希.URL哈希对后端服务器做负载,并且还支持对后端服务器的健康检查. 完整的Nginx代理配置如下: user nginx ngin