windows下搭建nginx服务并实现基于端口与路径转发
·
windows下搭建nginx
nginx下载
- 下载地址:http://nginx.org/en/download.html
- 下载截图 直接解压即可

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/+
更多推荐
所有评论(0)