laravelnginxnginx-reverse-proxyqgisvhosts

How do i configure a QGIS Server on an NGINX powered web server that is already serving a Laravel App


I have successfully set up a QGIS Server on an Ubuntu box.

I would like to access some maps on a url say: 121.123.124.124/qgisserver

I am currently accessing my laravel app via 121.123.124.124/

I have configured the virtual host for the qgisserver as below:

server {
    listen 80;
    server_name 121.123.124.124;

    location = /qgisserver {
        gzip           off;
        include        fastcgi_params;
        fastcgi_pass   unix:/var/run/qgisserver.socket;
    }
}

following the training manual here https://docs.qgis.org/3.22/en/docs/server_manual/getting_started.html#installation-on-debian-based-systems

the laravel app host file looks like this:

server {
    listen 80;
    server_name 121.123.124.124;
    
    root /var/www/html/laravel-app/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

I have enabled the qgisserver virtual host by symlinking it in the sites-enabled folder and restarting the nginx service.

However when i access 121.123.124.124/qgisserver , it returns the default laravel 404 error page.

How can i successfully access my qgis maps via the 121.123.124.124/qgisserver location and still access the app at 121.123.124.124/

Thank you.


Solution

  • You shouldn't use a separate server block for that, especially with the same server name! You should already receive an nginx message like nginx: [warn] conflicting server name "121.123.124.124" on 0.0.0.0:80, ignored; doesn't it warns you that you are doing something wrong? Put that location into the same server block where laravel app is served. To prevent QGIS Server URLs from interfering with your laravel app in any way, use the ^~ location modifier:

    location ^~ /qgisserver {
        gzip           off;
        include        fastcgi_params;
        fastcgi_pass   unix:/var/run/qgisserver.socket;
    }