win7 搭建nginx反向代理服务器 代理tomcat

逃离我推掉我的手 2022-06-02 01:08 441阅读 0赞

1.下载Nginx 资源包 http://nginx.org/en/download.html与tomcat :https://tomcat.apache.org/download-80.cgi

a.nginx

Center

b.tomcat8

Center 1

2.分别将压缩包加压到D盘根目录

Center 2

//

Center 3

3.在tomcat 的weapps 下创建test文件夹,并新建index.html文件。html内容自定义即可

Center 4

4.启动tomcat 在浏览器输入:http://localhost:8080/test

Center 5

5.在nginx的conf目录下找到nginx.conf, 并打开

Center 6

6.修改 server里面的选项 修改下面对应的红色字体即可。

其中(;号不要少)

listen 10101; 为nginx监听端口

proxy_pass http://localhost:8080; 为代理的地址

  1. server {
  2. listen 10101;
  3. server_name my_servers;
  4. #charset koi8-r;
  5. #access_log logs/host.access.log main;
  6. #location / {
  7. # root html;
  8. # index index.html index.htm;
  9. #}
  10. location / {
  11. root html;
  12. index index.html index.htm;
  13. proxy_pass http://localhost:8080;
  14. }
  15. #error_page 404 /404.html;
  16. # redirect server error pages to the static page /50x.html
  17. #
  18. error_page 500 502 503 504 /50x.html;
  19. location = /50x.html {
  20. root html;
  21. }

7.进入nginx 目录 打开命令窗口

运行 start nginx 即可

Center 7

8.在浏览器输入 http://localhost:10101/test/ 即可访问成功

Center 8

以上配置仅为nginx 指定单个tomcat的 简单配置。

2. 配置多个tomcat 负载均衡

这里只需修改nginx.conf配置文件即可

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;
  4. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  5. # '$status $body_bytes_sent "$http_referer" '
  6. # '"$http_user_agent" "$http_x_forwarded_for"';
  7. #access_log logs/access.log main;
  8. sendfile on;
  9. #tcp_nopush on;
  10. #keepalive_timeout 0;
  11. keepalive_timeout 65;
  12. #gzip on;
  13. #设定负载均衡的服务器列表
  14. #weight参数标识权值,权值越高被分配到的几率越大
  15. upstream my_servers { server 192.168.0.119:8888 weight=10; server 192.168.0.119:8040 weight=5; }
  16. server {
  17. listen 10101;
  18. server_name my_servers;
  19. #charset koi8-r;
  20. #access_log logs/host.access.log main;
  21. #location / {
  22. # root html;
  23. # index index.html index.htm;
  24. #}
  25. location / {
  26. root html;
  27. index index.html index.htm;
  28. proxy_pass http://my_servers;
  29. }

发表评论

表情:
评论列表 (有 0 条评论,441人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Nginx服务器反向代理

    好久没有用nginx服务器了,这次公司又用到了,就写写一般公司用nginx的反向代理把。 业务场景:由于我们是手机端只能访问一个ip,通过那个ip上部署的nginx来访问内网