GeoServer – How to Allow CORS on GeoServer with Tomcat and Nginx

corsgeoservernginxtomcat

I've used this procedure for install GeoServer on a server based on Ubuntu 20.04 with Tomcat and Nginx. At the end I've putted under HTTPS my subdomain.

I can see without problems the WMS services and infact I've created this map that use eight WMS link.

The problem comes when I try to pick up the informations from the pixels because I see into console log many problems about CORS origin.

So, I've followed this procedure to activate CORS on GeoServer. After the edit of web.xml I've reloaded GeoServer clicked on Reload into web user interface but GeoServer goes offline with the error:

HTTP Status 404 – Not Found

Type Status Report

Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.37

I've restarted Tomcat and Nginx with:

systemctl restart tomcat
systemctl restart nginx

and now I see another error:

HTTP Status 404 – Not Found

Type Status Report

Message The requested resource [/geoserver/] is not available

Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.37

How I can solve this problem?

EDIT 1:

Inside the logs (geoserver/data/logs) there aren't indication about the problem. If I comment again the rows edited inside web.xml and use systemctl restart tomcat it is possible to use again GeoServer.

EIDT 2:

Inside web.xml I've this rows that are commented:

   <!-- Uncomment following filter to enable CORS
<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>
-->
.
.
.
   <!-- Uncomment following filter to enable CORS
    <filter-mapping>
        <filter-name>cross-origin</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
-->

I uncomment the rows and then save the file.

Best Answer

You seem to be following the instructions for a jetty install rather than the ones for tomcat with the result that tomcat is trying to process a Jetty jar and (understandably) crashes.

Related Question