windows下搭建nginx服务并实现基于端口与路径转发

windows下搭建nginx

nginx下载

nginx使用

  • nginx不能通过双击nginx.exe启动,需要在cmd命令行中通过命令启动。
  • 启动cmd命令行,进入nginx所在路径
启动命令
  • start nginx
停止命令
  • nginx -s stop 直接退出
  • nigix -s quit 保存并退出
重新加载配置文件
  • nginx -s reload

nginx配置

  • 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表示将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;
        }
    }
}
# 在做请求转发时,主要注意proxy_pass后/符号的添加,不加/表示访问 http://localhost:8080/demo+  加/表示访问http://localhost:8080/+
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值