AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 835861
Accepted
Vasil Koicev
Vasil Koicev
Asked: 2017-03-03 04:02:51 +0800 CST2017-03-03 04:02:51 +0800 CST 2017-03-03 04:02:51 +0800 CST

Nginx + Tomcat 8 + SSL 反向代理

  • 772

我正在关注这个例子:

https://devtidbits.com/2015/12/08/nginx-as-a-reverse-proxy-to-apache-tomcat/

我的目标是让 Tomcat 运行并在其前面运行 Nginx。

我想有类似这样的结构:

test.com/ - 来自 nginx 的静态站点

test.com/tomcat - tomcat 管理器(带有工作链接)

test.com/app - tomcat 应用程序(部署在 /app on tomcat)

app2.test.com/app

我的 Nginx 配置是:

upstream tomcat {
    server 127.0.0.1:8080 fail_timeout=0;
}
server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    include snippets/ssl-test.com.conf;
    include snippets/ssl-params.conf;
    root /var/www/test.com/html;
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    server_name test.com www.test.com;
    location / {
        # First attempt to serve request as file, then as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
    location ~ /.well-known {
                allow all;
        }

    location ~ ^/tomcat(/?)(.*)$ {  # OOPS!
      proxy_pass http://tomcat/$2$is_args$args;  # OOPS!
    }

    location /tomcat/ {
       include proxy_params;
       proxy_pass http://tomcat/;

        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  expires 1M;
 }
}

先感谢您!

ssl nginx reverse-proxy tomcat8
  • 1 1 个回答
  • 3824 Views

1 个回答

  • Voted
  1. Best Answer
    Tero Kilkanen
    2017-03-03T04:37:55+08:002017-03-03T04:37:55+08:00

    尝试以下一个而不是您的两个tomcat位置:

    location ~ /tomcat(.*)$ {
        include proxy_params;
        proxy_pass http://tomcat$1$is_args$args;
    
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    • 0

相关问题

  • 如何使用 Tomcat 5.5 更新 SSL 证书

  • 为 IIS6 自行生成 SSL 证书?

  • plesk 上的域和子域 ssl 访问

  • 如何设置 SSL 邮件服务器?

  • 如何通过 SVN 命令行接受 SSL 证书?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve