Nginx 反向代理配置基础版

是在location中配置的,关键字【proxy pass】
实现方式如下【我们通过反向代理到外部其他网站】 
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {  #一个server配置就是一个主机,可以配置多个【虚拟主机】
        listen       80;
        server_name  localhost guos.com; #【支持域名、主机名,因为在hosts里有localhost对应的就是 127.0.0.1】
        location / {
        proxy_pass  http://www.baidu.com; #【这里也可以直接匹配ip地址http://192.168.66.131即另外一台虚拟机,有了proxy_pass后面的内容就不会匹配了;另外这里没有配置证书,所以无法代理到https协议相关的网站】
            root   html; #【此时的root指的是/usr/local/nginx】
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

当我们在地址栏中输入guos.com时,会直接来到百度的首页

 

posted @ 2022-07-08 16:49  以赛亚  阅读(56)  评论(0编辑  收藏  举报