我正在尝试建立一个网站,该网站可以从与该网站相同的DigitalOcean Droplet上的GeoServer实例访问WMS服务。 Droplet是具有以下功能的Ubuntu 18.04服务器: -tomcat8 -postgresql-10 -openjdk-8-jdk-无头 -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?

这是我当前对该网站的Nginx配置:

    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;
        }

    }

我尚未部署防火墙,并且在子域(也在localhost:8080上)有另一个tomcat Webapp,Nginx正在使用proxy_pass正确为其提供服务。

最佳答案

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/

然后,我添加了一个指向子站IP的新子域:gs.foo.bar

然后,将Geoserver.war重命名为ROOT.war,然后将其部署到新tomcat实例中的ROOT上,然后再将其放置在webapps文件夹中。

然后,我为该站点创建了以下Nginx配置:

server {
    client_max_body_size 100m;
    server_name gs.foo.bar;

    location / {
        proxy_pass http://127.0.0.1:8081;
    }

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.