CentOS7 nginx反向代理——将80端口请求转发到8080

反向代理的意思是以代理服务器(这里也就是nginx)来接收网络上的请求,也就是url(默认是80端口)

nginx配置反向代理后可以将不同二级域名的请求转发到不同的可以提供相应服务的端口或者ip和端口,也就是说,在你访问demo1.bau.com时,实际访问的是demo2.baudu.com

下面是配置反向代理

环境:
	Nginx,(Tomcat)

命令行运行:

//寻找nginx.conf
whereis nginx.conf

//进入文件夹
cd /etc/nginx

//打开配置文件
vi nginx.conf

//增加server层信息(Server层信息要放在http内)
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name 127.0.0.1:8080;
        root /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        		//xx.xx.xx.xx代表你的域名或者ip
                proxy_pass http://xx.xx.xx.xx:8080;
        }

        error_page 404 /404.html;
                location = /40x.html {
                }

        error_page 500 502 503 504 /50x.html;
                location = /50x.html {
                }
}

猜你喜欢

转载自blog.csdn.net/weixin_43911969/article/details/106805072