Nginx 反向代理配置

什么是nginx

nginx可以提供的服务有:

1. web 服务
2. 负载均衡 (反向代理)
3. web cache(web 缓存

nginx常用命令

  • 测试配置文件:${Nginx}/sbin/nginx -t
  • 启动命令:${Nginx}/sbin/nginx
  • 停止命令:${Nginx}/sbin/nginx -s stop/quit
  • 重启命令:${Nginx}/sbin/nginx -s reload
  • 查看进程命令:ps -ef | grep nginx
  • 平滑重启:kill -HUP [Nginx主进程号(即ps命令查到的PID)]

nginx实现反向代理配置

1.打开 ${Nginx}/conf/nginx.conf 文件

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    # 这个server配置表示访问localhost:8081地址 将请求转发到这个server下定义的location位置上
	server {
        listen       8081;
        server_name  localhost;
        # 这个location表示将localhost:8081地址转发到html文件夹下的index2.html首页上
        location / {
            root   html;
            index  index2.html index.htm;
        }
    }
    # 这个server表示访问localhost:80地址 将请求转发到这个server下定义的location位置上
    server {
        listen       80;
        server_name  localhost;
        # 这个location表示将localhost:80请求 转发到index.html文件上
	 location / {
			root   html;
            index  index.html index.htm;
		}
        #location / {
            #proxy_pass http://www.zzdy.wang:18537/;
       # }
	#这个location表示将localhost:80/demo/开头的请求 转发到http://localhost:8080/服务上
         location /demo {
			proxy_pass http://localhost:8080/;
		}
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
            root   html;
         }
    }
# nginx:http转发到https
    HTTPS server
     server {
		listen 8069;
		server_name www.zzdy**.cn;
		rewrite ^(.*)$ https://$host$1 permanent;
	}
}
# 在做请求转发时,一定要注意proxy_pass后/符号的添加,不加/表示访问 http://localhost:8080/demo+/表示访问http://localhost:8080/+
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值