0

I have a site example.ru on a remote server with ip 90.156.XXX.XX, it runs on https.

I installed GeoServer on this remote machine and ran it on 90.156.XXX.XX:8080, i.e. http://90.156.XXX.XX:8080/geoserver/

When I was trying to get data from the http-link, I got the following error: Mixed Content. The page at was loaded over HTTPS but requested an insecure resource. This request has been blocked the content must be served over HTTPS.

I solved it the way described here: https://dev.to/iamtekson/using-nginx-to-put-geoserver-https-4204

I now have GeoServer responding to https://example.ru/geoserver/ which is the same as https://90.156.XXX.XX/geoserver/

And if I type in a browser line, for example, https://90.156.XXX.XX/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.1.1&LAYER=push_how_old:buildings_pushkino_how_old_wmts&STYLE=&TILEMATRIX=EPSG:900913:12&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL=2478&TILEROW=1275, I get the file

But the site itself with the code

map.addSource("buildings_pushkino_how_old", {
          type: "vector",
          tiles: [
            "https://90.156.XXX.XX/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.1.1&LAYER=push_how_old:buildings_pushkino_how_old_wmts&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL={x}&TILEROW={y}",
          ],
          bounds: [37.78089132, 55.96388819, 37.93968874, 56.060285621],
        });

gives out errors of the kind:

Access to fetch at 'https://90.156.XXX.XX/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.1.1&LAYER=push_how_old:buildings_pushkino_how_old_wmts&STYLE=&TILEMATRIX=EPSG:900913:12&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL=2478&TILEROW=1275' from origin 'https://example.ru' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

This is what the nginx config of my site looks like:

server {
listen 80;
listen [::]:80;
server_name example.ru www.example.ru;
return 301 https://example.ru$request_uri;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name www.example.ru;
return 301 https://example.ru$request_uri;
ssl_certificate /etc/nginx/ssl/example/example.crt;
ssl_certificate_key /etc/nginx/ssl/example/example.key;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.ru;
ssl_certificate /etc/nginx/ssl/example/example.crt;
ssl_certificate_key /etc/nginx/ssl/example/example.key;
root /var/www/example;
index index.html;

add_header 'Access-Control-Allow-Origin' '<https://example.ru>' always;

location / {
    try_files $uri $uri/ =404;
}

location /geoserver {
        proxy_pass <http://127.0.0.1:8080/geoserver>;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
     }

In the Geoserver web.xml file, I removed the comments from these lines:

       <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>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

And still the error remains. Can you please tell me what else I can do or where I made a mistake?

9
  • Did you make any cors settings?
    – Ian Turton
    Commented Apr 5 at 17:55
  • @IanTurton, Only the ones I described in the question
    – Ilya
    Commented Apr 5 at 18:21
  • Are you running tomcat?
    – Ian Turton
    Commented Apr 5 at 19:11
  • @IanTurton , no
    – Ilya
    Commented Apr 5 at 19:22
  • Then those changes will make no difference,
    – Ian Turton
    Commented Apr 6 at 8:59

1 Answer 1

1

I figured out what the cause was

After transferring GeoServer
from http://90.156.XXX.XX:8080/geoserver/
to https://90.156.XXX.XX/geoserver/, which is the same as https://example.ru/geoserver/
when connecting the layer

map.addSource("buildings_pushkino_how_old", {
          type: "vector",
          tiles: [
            "https://90.156.XXX.XX/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.1.1&LAYER=push_how_old:buildings_pushkino_how_old_wmts&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL={x}&TILEROW={y}",
          ],
          bounds: [37.78089132, 55.96388819, 37.93968874, 56.060285621],
        });

instead of https://90.156.XXX.XX/geoserver/ should have specified https://example.ru/geoserver/ and CORS changes in web.xml were not needed in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.