I'm trying to build a website with access to WMS services from a GeoServer instance on the same DigitalOcean droplet as the website. The droplet is an Ubuntu 18.04 server with
– tomcat8
– postgresql-10
– openjdk-8-jdk-headless
– nginx
I deployed GeoServer from a web archive and if I connect using ssh from my local machine and map the droplets 8080 port to port 63334 on my local machine, I can access the GeoServer web app from http://localhost:63334/bcp_geoserver/web/ and I can also use the WMS services in a simple Leaflet map using http://localhost:63334/bcp_geoserver/LCFP/wms as an address in an HTML file on my local machine. So GeoServer appears to be working correctly.
However, if I change the address in the HTML file to http://localhost:8080/bcp_geoserver/LCFP/wms and upload it to my nginx website root folder on the droplet, I get a connection refused error for the wms services if I try to access the website through the Internet. I assume this is because I don't have a proper Nginx configuration for this website. Is there a way to configure Nginx so that the website can use the WMS services?
This is my current Nginx configuration for this website:
server {
listen 80;
server_name foo.bar;
root /var/www/foo.bar/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location /bcp_geoserver {
proxy_pass http://localhost:8080/bcp_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;
}
}
I have not deployed a firewall and I have another tomcat webapp on a subdomain (also at localhost:8080) and Nginx is serving it properly with proxy_pass.
Best Answer
I wasn't able to figure out what the exact problem was (whether Nginx, conflicts with the other webapp on the same port, or something else) so I changed course. I installed another copy of tomcat and set it to use different ports from the default following this page: https://linoxide.com/ubuntu-how-to/install-tomcat-8-ubuntu-16-04-multiple-instances/
Then I added a new subdomain pointing to my droplet IP: gs.foo.bar
Then I deployed the Geoserver.war to ROOT in the new tomcat instance by renaming it as ROOT.war before placing it in the webapps folder.
Then I created the following Nginx configuration for the site:
Then for the address to the wms service in the html file I used http://gs.foo.bar/LCFP/wms. It works. This exposed the Geoserver webapp to the internet though, so I changed the default admin password.