首页 > 编程知识 正文

NGINX 反向代理,nginx反向代理啥意思

时间:2023-05-06 19:31:46 阅读:252750 作者:83

1 正向代理和反向代理

关于代理,其实我们大家都用过,其中比较常见的就是翻墙软件,也就是正向代理软件。

1.1正向代理

其原理图主要如下所示:

我们可以看到,通过代理,客户端使用Proxy来访问Server服务器,而隐藏了真实的服务器。其实黑客们常常也是这么做来隐藏真实身份。

1.2 反向代理

其原理图如下所示

由上图我们可以看到,当客户端访问某个服务器的时候,他访问的不是真实的服务器,而是代理服务器。然后由代理服务器对客户端的需求进行转发。

这样做主要有如下好处

(1) 防止黑客入侵,隐藏真实的服务器地址。

(2) 可以通过Proxy代理实现负载均衡,提高访问服务器集群的性能。

(3)单一职能,可以搭建高性能的集群,提高服务器使用的性价比。

2 Nginx代理

好了,上文介绍那么多,我们进入今天的正题,Nginx服务器。

基本的操作,本文不在赘述。详细见参考文献。

3 Nginx简单的配置

简单的配置,找到nginx.conf文件,nginx.conf内部有默认的配置,把他们设定为我们自己需要的跳转地址即可。

我的配置如下所示

#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}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; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name 127.0.0.1; #charset koi8-r; #access_log logs/host.access.log main; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ .php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}location /{proxy_pass http://www.baidu.com/;} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
这样通过访问127.0.0.1:80 就会跳转到www.baidu.com上面了,然后由DNS解析成具体的服务器地址。


4 遇到的Bug

Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:UsersAdministrator>d:D:>nginx-1.10.1'nginx-1.10.1' 不是内部或外部命令,也不是可运行的程序或批处理文件。D:>cd nginx-1.10.1D:nginx-1.10.1>nginx.exe -s stopnginx: [error] CreateFile() "D:nginx-1.10.1/logs/nginx.pid" failed (2: The system cannot find the file specified)D:nginx-1.10.1>nginx.exe -s stopnginx: [error] CreateFile() "D:nginx-1.10.1/logs/nginx.pid" failed (2: The system cannot find the file specified)D:nginx-1.10.1>
主要解决办法

这个是因为本地的Nginx.exe 未打开,或者打开过多导致的。


5 参考网页

windows 下配置 Nginx 常见问题
http://www.cnblogs.com/Joans/p/4409910.html
Nginx开发从入门到精通
http://tengine.taobao.org/book/
Nginx安装与使用
http://www.cnblogs.com/skynet/p/4146083.html
Windows下Nginx初入门
http://blog.csdn.net/u010221213/article/details/51434171
Nginx在Windows下的安装
http://www.2cto.com/os/201505/399270.html
Nginx 配置从零开始
http://www.open-open.com/lib/view/open1419826381531.html
nginx 学习笔记(2) nginx新手入门
http://www.cnblogs.com/davidwang456/p/3426362.html
nginx启动、重启、关闭
http://www.cnblogs.com/jianxie/p/3990377.html
(转)Nginx反向代理设置 从80端口转向其他端口
http://www.cnblogs.com/94cool/p/3927084.html
Windows下Nginx的启动、停止等命令
http://blog.csdn.net/ppby2002/article/details/38681345
Nginx反向代理和负载均衡部署指南
http://www.cnblogs.com/jacktang/p/3669115.html
elk+redis 搭建nginx日志分析平台
http://www.cnblogs.com/yjf512/p/4199105.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。