I have QGIS server working. The standard functionality is to add ?map=path/to/projectfile.qgs to the server URL. So you can dynamically switch between projects in your webapplication. Now I make my projects and upload my projectfile to the server to get them working in my application. That works fine.
But I can also store the project in the database. It would be much nicer if I could tell my application to use a project from my database. Skipping the cumbersome file update procedure.
Researching this I came across this info from the QGis documentation: https://docs.qgis.org/3.16/en/docs/server_manual/config.html in the section: 5.2. Environment variables I see the following info:
QGIS_PROJECT_FILE
The .qgs or .qgz project file, normally passed as a parameter in the query string (with MAP), you can also set it as an environment variable (for example by using mod_rewrite Apache module). postgresql://localhost:5432?sslmode=disable&dbname=mydb&schema=myschema&project=myproject
So you can point to a projectfile in the database for the default projectfile. But that's not what I want. I want to do it dynamically.
What I want is to have something like ?map=projectfile_in_my_database. And specifiy in my conf / environment on the server where these are stored in de DB.
Is this possible?
You can use project files stored in a database (in my case it is postgres). How I did it.
psql service=myservicename
and set fastcgi params on nginx
fastcgi_param PGSERVICEFILE /home/qgis/.pg_service.conf;
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
gzip off;
include fastcgi_params;
fastcgi_param QGIS_PROJECT_FILE postgresql:///?service=myservicename&schema=public&project=testproject;
fastcgi_pass unix:/var/run/fcgiwrap.socket;;
}