Springboot / tomcat / apache反向代理,其中哪个应用程序设置了回复标头

发布于 2025-02-04 06:57:37 字数 5421 浏览 3 评论 0原文

我有一个在Tomcat中运行的Springboot(没有安全性)应用程序,并且服务器上的Apache反向代理。 提出邮政请求时,返回状态403。

我怀疑Tomcat或Apache反向代理负责返回403。 HTTP请求或HTTP响应中的哪些信息导致403返回代码? 我该如何解决?

pom.xml

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.4</version>
</dependency>

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>${open-api}</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
</dependency>

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>jfreechart</artifactId>
    <version>1.0.19</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

httpd.conf

SSLCipherSuite 'kEECDH+ECDSA kEECDH kEDH HIGH +SHA !aNULL !eNULL !LOW !MEDIUM !MD5 !EXP !DSS !PSK !SRP !kECDH SSLHonorCipherOrder On
SSLRandomSeed startup file:/dev/urandom 2048
SSLRandomSeed connect builtin

DocumentRoot /apache/htdocs

AddDefaultCharset utf-8

<VirtualHost *:80>
  RewriteEngine   On
  RewriteRule     ^/(.*)$   https://%{HTTP_HOST}/$1    [redirect,last]
  <Directory /apache/htdocs>
    Require all granted
    Options None
    AllowOverride None
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  SSLEngine On
  <Directory /apache/htdocs>
    Require all granted
    Options None
    AllowOverride None
  </Directory>
  SSLEngine on
  SSLCertificateFile "/etc/letsencrypt/live/www.guli.com/fullchain.pem"
  SSLCertificateKeyFile "/etc/letsencrypt/live/www.guli.com/privkey.pem"
</VirtualHost>


<IfModule mod_proxy.c>
  <Location "/">
    ProxyPass "http://localhost:50080/main/" connectiontimeout=5 timeout=600
    ProxyPassReverse "http://localhost:50080/main/"
    ProxyPassReverseCookiePath "/main/" "/"
    ProxyPreserveHost On
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
    Header always set Access-Control-Max-Age "600"
  </Location>
# so läuft mal: http://www.guli.com
  <Location "/email">
    ProxyPass "http://localhost:50099/email"
    ProxyPassReverse "http://localhost:50099/email"
    ProxyPassReverseCookiePath "/email" "/"
    RequestHeader set X-Forwarded-Prefix "/email"
    ProxyPreserveHost On
  </Location>
# /ta/swagger-ui.html 
  <Location "/ta">
    ProxyPass "http://localhost:50086/ta"
    ProxyPassReverse "http://localhost:50086/ta"
    ProxyPassReverseCookiePath "/ta" "/"
    RequestHeader set X-Forwarded-Prefix "/ta"
    ProxyPreserveHost On
  </Location>
# pres/swagger-ui.html
  <Location "/pres">
    ProxyPass "http://localhost:50083/pres"
    ProxyPassReverse "http://localhost:50083/pres"
    ProxyPassReverseCookiePath "/pres" "/"
    RequestHeader set X-Forwarded-Prefix "/pres"
    ProxyPreserveHost On
  </Location>
  <Location "/guli-web">
    ProxyPass "http://localhost:50096/guliadmin-web" connectiontimeout=5 timeout=600
    ProxyPassReverse "http://localhost:50096/guliadmin-web"
    ProxyPassReverseCookiePath "/guliadmin-web" "/guliadmin-web"
    ProxyPreserveHost On
  </Location>
  <Location "/.well-known">
    ProxyPass "!"
  </Location>
  ProxyRequests Off
  ProxyVia Off
  ProxyStatus On
</IfModule>

I've a springBoot (without security) application running in Tomcat and with Apache reverse proxy on the server.
When making a POST request, the status 403 is returned.

I suspect Tomcat or apache reverse proxy to be responsible for returning 403.
Which information in the HTTP request or HTTP response is causing the 403 return code ?
And how can I fix it ?

enter image description here

pom.xml

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.4</version>
</dependency>

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>${open-api}</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
</dependency>

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>jfreechart</artifactId>
    <version>1.0.19</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

httpd.conf

SSLCipherSuite 'kEECDH+ECDSA kEECDH kEDH HIGH +SHA !aNULL !eNULL !LOW !MEDIUM !MD5 !EXP !DSS !PSK !SRP !kECDH SSLHonorCipherOrder On
SSLRandomSeed startup file:/dev/urandom 2048
SSLRandomSeed connect builtin

DocumentRoot /apache/htdocs

AddDefaultCharset utf-8

<VirtualHost *:80>
  RewriteEngine   On
  RewriteRule     ^/(.*)$   https://%{HTTP_HOST}/$1    [redirect,last]
  <Directory /apache/htdocs>
    Require all granted
    Options None
    AllowOverride None
  </Directory>
</VirtualHost>

<VirtualHost *:443>
  SSLEngine On
  <Directory /apache/htdocs>
    Require all granted
    Options None
    AllowOverride None
  </Directory>
  SSLEngine on
  SSLCertificateFile "/etc/letsencrypt/live/www.guli.com/fullchain.pem"
  SSLCertificateKeyFile "/etc/letsencrypt/live/www.guli.com/privkey.pem"
</VirtualHost>


<IfModule mod_proxy.c>
  <Location "/">
    ProxyPass "http://localhost:50080/main/" connectiontimeout=5 timeout=600
    ProxyPassReverse "http://localhost:50080/main/"
    ProxyPassReverseCookiePath "/main/" "/"
    ProxyPreserveHost On
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
    Header always set Access-Control-Max-Age "600"
  </Location>
# so läuft mal: http://www.guli.com
  <Location "/email">
    ProxyPass "http://localhost:50099/email"
    ProxyPassReverse "http://localhost:50099/email"
    ProxyPassReverseCookiePath "/email" "/"
    RequestHeader set X-Forwarded-Prefix "/email"
    ProxyPreserveHost On
  </Location>
# /ta/swagger-ui.html 
  <Location "/ta">
    ProxyPass "http://localhost:50086/ta"
    ProxyPassReverse "http://localhost:50086/ta"
    ProxyPassReverseCookiePath "/ta" "/"
    RequestHeader set X-Forwarded-Prefix "/ta"
    ProxyPreserveHost On
  </Location>
# pres/swagger-ui.html
  <Location "/pres">
    ProxyPass "http://localhost:50083/pres"
    ProxyPassReverse "http://localhost:50083/pres"
    ProxyPassReverseCookiePath "/pres" "/"
    RequestHeader set X-Forwarded-Prefix "/pres"
    ProxyPreserveHost On
  </Location>
  <Location "/guli-web">
    ProxyPass "http://localhost:50096/guliadmin-web" connectiontimeout=5 timeout=600
    ProxyPassReverse "http://localhost:50096/guliadmin-web"
    ProxyPassReverseCookiePath "/guliadmin-web" "/guliadmin-web"
    ProxyPreserveHost On
  </Location>
  <Location "/.well-known">
    ProxyPass "!"
  </Location>
  ProxyRequests Off
  ProxyVia Off
  ProxyStatus On
</IfModule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云仙小弟 2025-02-11 06:57:37

我们看到响应标头在 /位置< /em>中设置为< /em>,而a /ta 位置< /em>部分。
如所说的

We see the response headers being set in the / Location while there's a /ta Location section.
As says the Location documentation, the sections are processed in the order they appear, which means the / should logically be the last section.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文