spring - 如何在 NGINX 中将 http 指向 https 子域?
问题描述
我正在开发一个 Spring Boot 应用程序,它为 3 种类型的用户提供内容。所有三个用户都“生活”在同一个应用程序中。我想将 NGINX 配置为 1)将所有 http 重定向到 https 和 2)重定向流量,如下所示:
http 到https://www.example.com
http://b2b.example.com到https://b2b.example.com/b2b(理想情况下不显示“/b2b”。这里所有的 b2b spring boot 端点都在监听)
到目前为止,这是我的 NGINX 配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.com www.example.com;
ssl on;
ssl_certificate ...;
ssl_certificate_key ...;
ssl_session_cache shared:SSL:10m;
access_log ...;
error_log ...;
location / {
proxy_pass http://localhost:5050;
proxy_set_header Host $host;
# re-write redirects to http as to https, example: /home
proxy_redirect http:// https://;
}
}
server {
listen 443;
server_name b2b.example.com;
ssl on;
ssl_certificate ...;
ssl_certificate_key ...;
ssl_session_cache shared:SSL:10m;
access_log ...;
error_log ...;
location / {
proxy_pass http://localhost:5050/b2b;
proxy_set_header Host $host;
# re-write redirects to http as to https, example: /home
proxy_redirect http:// https://;
}
}
在 Sring Boot 方面,所有 B2B 端点都在侦听以“B2B”开头的模式。例如,这些用户的登录页面是 .../B2B/login。现在,如果我访问 b2b.example.com,我会被重定向到 b2b.example.com/B2B/login。我想要的是浏览器显示“B2B.example.com/login”并显示“/B2B/login”页面。所有在 URL 中省略“/B2B”部分的 B2B 网站。
解决方案
推荐阅读
- python - 关于python socket UDP
- php - 查询在 phpmyadmin 上工作但不在 php 脚本中
- oracle - Oracle FORMS 12C - 使用 CLIENT_TEXT_IO webutil 从 oracle 表单应用程序生成受密码保护的文件
- postgresql - 在 postgres 中选择 json 值 frob jsonb 列
- python - 如何提高pyqtgraph中大量TextItem的绘制速度
- xamarin - 在 Uno 平台上如何使用 Preferences.Set 命令
- java - Saxon 10 HE - 每个 Java 扩展类是否需要一个命名空间?
- ios - SwiftUI 具有 @Environment(\.presentationMode) 用于消除视图行为不端
- redhat - 安全套接字代理代理侦听器错误
- mysql - MYSQL传递存储过程变量IN子句