klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

podman配置geoserver跨域问题 #859

Open klren0312 opened 2 weeks ago

klren0312 commented 2 weeks ago

1. 进入镜像终端

podman exec -it 镜像id /bin/bash

2. 安装vim

chmod 777 /tmp && apt-get update && apt install vim -y

3. 编辑tomcat配置文件

vim /usr/local/tomcat/webapps/geoserver/WEB-INF/web.xml

直接到文件中粘贴

<filter>
      <filter-name>cross-origin</filter-name>
      <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
      <init-param>
        <param-name>chainPreflight</param-name>
        <param-value>false</param-value>
      </init-param>
      <init-param>
        <param-name>allowedOrigins</param-name>
        <param-value>*</param-value>
      </init-param>
      <init-param>
        <param-name>allowedMethods</param-name>
        <param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
      </init-param>
      <init-param>
        <param-name>allowedHeaders</param-name>
        <param-value>*</param-value>
      </init-param>
    </filter>
    <filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

4. 下载指定jetty版本

a. 访问对应geoserver版本的pom文件,查看jetty版本,我这里是2.25.4

https://github.com/geoserver/geoserver/blob/2.25.4/src/pom.xml

b. 下载指定jetty的jar包

https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlets/9.4.55.v20240627 https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util/9.4.55.v20240627

右键获取链接,到镜像中wget下载即可 image image

cd /usr/local/tomcat/webapps/geoserver/WEB-INF/lib
wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlets/9.4.55.v20240627/jetty-servlets-9.4.55.v20240627.jar
wget https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-util/9.4.55.v20240627/jetty-util-9.4.55.v20240627.jar

5. 重启镜像

podman restart 7f8b0dedd3d3

image