热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Nginxhttp代理服务器设置方法

如何利用Nginx架设Http代理服务器Nginx一般都是作为web服务器和反向代理服务器存在的,我们也可以把它用作一个Http代理服务器。操作很简单,只需要修改一下它的配置文件nginx.conf添加一个Server字段。server{listen8080;location/{proxy_passhttp://$
如何利用Nginx架设Http代理服务器
Nginx 一般都是作为web服务器和反向代理服务器存在的,我们也可以把它用作一个Http代理服务器。操作很简单,只需要修改一下它的配置文件nginx.conf 添加一个Server字段。
server {
    listen 8080;
    location / {
    proxy_pass http://$http_host$request_uri;
    access_log off;
    }
}
另外还需要在http字段内,用resolver指定一下DNS服务器,否则会发生 “nginx 502 bad gateway” 的错误。我采用是Google提供的DNS服务:
resolver 8.8.8.8;
修改完之后需要重启一下nginx服务器:
nginx -s reload
最后,修改一下浏览器代理设置的,访问www.ip.cn
,就能看到IP地址发生变化了。

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#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;
resolver 8.8.8.8;
sendfile        on;
    #tcp_nopush     on;
#keepalive_timeout  0;
    keepalive_timeout  65;
#gzip  on;
server {
        listen       8080;
        #server_name  localhost;
#charset koi8-r;
#access_log  logs/host.access.log  main;
#location / {
        #    root   html;
        #    index  index.html index.htm;
        #}
location / {
                proxy_pass http://$http_host$request_uri;
                access_log off;
        }
error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

同时使用两个代理端口的配置
#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;
resolver 8.8.8.8;
#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 9999;
        location / {
            proxy_pass http://$http_host$request_uri;
            access_log off;
            }
        }
server {
        listen       8080;
        #server_name  localhost;
#charset koi8-r;
#access_log  logs/host.access.log  main;
#location / {
        #    root   html;
        #    index  index.html index.htm;
        #}
location / {
                proxy_pass http://$http_host$request_uri;
                access_log off;
        }
#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;
        #}
# 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;
    #    server_name  localhost;
#    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
#    ssl_session_timeout  5m;
#    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;
#    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

推荐阅读
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • Docker的安全基准
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 本文将深入探讨PHP编程语言的基本概念,并解释PHP概念股的含义。通过详细解析,帮助读者理解PHP在Web开发和股票市场中的重要性。 ... [详细]
  • 本文详细介绍如何通过修改配置文件来隐藏Apache、Nginx和PHP的版本号,从而增强网站的安全性。我们将提供具体的配置步骤,并解释这些设置的重要性。 ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • This guide provides a comprehensive step-by-step approach to successfully installing the MongoDB PHP driver on XAMPP for macOS, ensuring a smooth and efficient setup process. ... [详细]
  • 探讨如何高效使用FastJSON进行JSON数据解析,特别是从复杂嵌套结构中提取特定字段值的方法。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 360SRC安全应急响应:从漏洞提交到修复的全过程
    本文详细介绍了360SRC平台处理一起关键安全事件的过程,涵盖从漏洞提交、验证、排查到最终修复的各个环节。通过这一案例,展示了360在安全应急响应方面的专业能力和严谨态度。 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
  • 深入解析 Spring Security 用户认证机制
    本文将详细介绍 Spring Security 中用户登录认证的核心流程,重点分析 AbstractAuthenticationProcessingFilter 和 AuthenticationManager 的工作原理。通过理解这些组件的实现,读者可以更好地掌握 Spring Security 的认证机制。 ... [详细]
author-avatar
小老虎颖儿
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有