借鉴文章
https://blog.csdn.net/weixin_44005802/article/details/135488448
1.官网下载链接:链接: https://nginx.org/en/download.html
2.将下载的zip包解压后,打开D:…\nginx-1.20.2\conf\nginx.conf,修改server为实际配置。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 809;
server_name localhost;
# localhost主页,直接访问 http://localhost 就会跳转
location / {
root html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# nginx代理 springboot项目1
location /get/method1 {
proxy_pass http://localhost:9999/get/method1;
# 关闭所有请求头
proxy_pass_request_headers off;
# 放行Host
proxy_set_header Host $host;
}
# nginx代理 springboot项目2
location /get/method2 {
proxy_pass http://localhost:9999/get/method2;
}
}
}
3.进入目录D:…\nginx-1.20.2
打开cmd,执行start nginx,可以看到一闪而过的弹窗,访问链接: http://localhost:809/,端口对应conf里的809.若成功访问Welcome to nginx!页面,即表示启动成功。