Nginx反向代理,转发请求至后端服务器

传送门:Nginx部署静态web工程

背景: 使用nginx作为反向代理服务器,将80请求转发至后端tomcat服务器
步骤:
1) 修改tomcat端口为8080
2) nginx中新建tomcats.conf配置文件
在这里插入图片描述
文件内容如下:

server {
        listen       80;
        server_name  localhost;(想要设置的访问地址)
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
             proxy_pass http://localhost:8080;(现在想要设置的路径的访问地址)
             root   html;
             index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

3) 修改nginx.conf配置文件
在这里插入图片描述
配置文件最后,添加这一行代码

include nginx/vhosts/*;

并,修改location
在这里插入图片描述
添加这一行代码

proxy_pass http://localhost:8080;

4) 重启nginx,如:访问localhost:/project1

即可成功访问

疑问:使用nginx作为反向代理,将80转发至后端tomcat后,怎么继续访问原nginx下部署的静态工程?

发布了135 篇原创文章 · 获赞 98 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/qq_35206244/article/details/101369488
今日推荐