寒窗轩,寒川的个人网络博客,记录互联网事,学习网络编程、分享工作经验、人生感悟,包括但不限于程序代码、数据库、Office办公、随笔等内容。

Nginx反向代理访问指定网站

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,用它来做代理访问网站,效果较好。下面以本地localhost访问本博客为例进行配置nginx反向代理服务器访问网站,请不要使用此技术做非法用途。采用的nginx版本为官方最新版1.21.3,系统为windows 10。nginx下载地址:http://nginx.org/en/download.html

下面是具体配置:

1、下载nginx,并解压到指定目录。

2、在conf目录中新建一个vhost目录,作为虚拟主机配置目录。

3、打开conf/nginx.conf,删除原有的Server,然后添加一行:include vhost/*.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;

    # 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;
    #    }
    #}
    include vhost/*.conf;
}

4、在conf/vhost下增加一个配置文件,localhost.conf,其配置如下:

server {
    listen       80;
    server_name  localhost;
    resolver     129.226.164.124;
    location / {
            root html;
            index index.html index.htm Default.aspx;
            proxy_pass http://huikon.cn;
            proxy_connect_timeout 120;
            proxy_read_timeout 600;
            proxy_send_timeout 600;
            send_timeout 600;
            proxy_redirect    off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

5、双击nginx.exe就可以启动了。


最后,赠送windows下nginx退出命令,如下:

nginx -s quit
taskkill  /im nginx.exe  -f

windows下nginx重新加载配置命令,如下:

nginx -s reload

把上述命令做成bat批处理文件,可实现双击后执行命令。

系统 2021-09-10 10:12:48 10 0 7528 nginx反向代理服务器
文章写得不错?我是土豪我要在线打赏!
在线打赏

昵称:

验证码:验证码

评论:

文章分类
系统
程序
数据
Office
随笔
热门文章
Excel文件内容很少,但文件很大,打开很慢、很卡怎么办?
Excel动态引用各表格指定单元格数据
开篇第一章
Excel文件内容很少,但文件很大,打开很慢怎么办?
如何利用python修改文件的创建时间,修改时间,访问时间
发现一个好网站——春燕文档
Ubuntu22.04中用thunar替换默认文件管理器,提示无法启动“TerminalEmulator“的首选应用程序
MySQL如何按每个分类查询10条数据,即MySQL如何每个分类查询10条数据
文章推荐
请不要奇怪,为什么最近博客的文章是几年前的内容
免责声明
关于博主
开篇第一章
随机推荐
OAuth认证协议原理分析及使用方法(转)
校内实习最后一周,放假在即
不合格的emlog插件开发者
简单而全面的sql查询教程(一)
网页中加入在线lrc歌词的方法
2020岁末总结
php检查数组中是否含有指定字符
Excel文件内容很少,但文件很大,打开很慢、很卡怎么办?
家中添丁
本博客的发展方向
友情连接
春燕网络
春燕文档
谢润的博客