고급 환경 설정

로그 작업

To log requests sent to the server, you have to set the following environment variables:

  • QGIS_SERVER_LOG_LEVEL

  • QGIS_SERVER_LOG_FILE

  • QGIS_SERVER_LOG_STDERR

Take a look on 환경 변수 to understand their meanings.

환경 변수

You can configure some aspects of QGIS Server by setting environment variables.

According to the HTTP server and how you run QGIS Server, there are several ways to define these variables. This is fully described in HTTP 서버 환경 설정.

QGIS_OPTIONS_PATH

Specifies the path to the directory with settings. It works the same way as QGIS application --optionspath option. It is looking for settings file in <QGIS_OPTIONS_PATH>/QGIS/QGIS3.ini.

QUERY_STRING

The query string, normally passed by the web server. This variable can be useful while testing QGIS server binary from the command line.

For example for testing a GetCapabilities request on the command line to a project that also requires a PostgreSQL connection defined in a pg_service.conf file:

PGSERVICEFILE=/etc/pg_service.conf QUERY_STRING="MAP=/path/to/test.qgs&SERVICE=WMS&REQUEST=GetCapabilities" /path/to/qgis_mapserv.fcgi

The result should be either the content of the GetCapabilities response or, if something is wrong, an error message.

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).

Note that you may also indicate a project stored in PostgreSQL, e.g. postgresql://localhost:5432?sslmode=disable&dbname=mydb&schema=myschema&project=myproject.

QGIS_SERVER_LOG_FILE

Specify path and filename. Make sure that server has proper permissions for writing to file. File should be created automatically, just send some requests to server. If it’s not there, check permissions.

QGIS_SERVER_LOG_FILE is deprecated since QGIS 3.4. File logging support will be removed in QGIS 4.0.

QGIS_SERVER_LOG_STDERR

Activate logging to stderr. It’s disabled by default. This variable has no effect when QGIS_SERVER_LOG_FILE is set.

  • 0 or false (case insensitive)

  • 1 or true (case insensitive)

MAX_CACHE_LAYERS

Specify the maximum number of cached layers (default: 100).

DISPLAY

This is used to pass (fake) X server display number (needed on Unix-like systems).

QGIS_PLUGINPATH

Useful if you are using Python plugins for the server, this sets the folder that is searched for Python plugins.

QGIS_SERVER_LOG_LEVEL

Specify desired log level. Available values are:

  • 0 or INFO (log all requests)

  • 1 or WARNING

  • 2 or CRITICAL (log just critical errors, suitable for production purposes)

QGIS_SERVER_PARALLEL_RENDERING

Activates parallel rendering for WMS GetMap requests. It’s disabled (false) by default. Available values are:

  • 0 or false (case insensitive)

  • 1 or true (case insensitive)

QGIS_SERVER_MAX_THREADS

Number of threads to use when parallel rendering is activated. Default value is -1 to use the number of processor cores.

QGIS_SERVER_CACHE_DIRECTORY

Specifies the network cache directory on the filesystem. The default directory is named cache and located in the profile directory.

QGIS_SERVER_CACHE_SIZE

Sets the network cache size in MB. The default value is 50 MB.

Settings summary

When QGIS Server is starting, you have a summary of all configurable parameters thanks to environment variables. Moreover, the value currently used and the origin is also displayed.

For example with spawn-fcgi:

export QGIS_OPTIONS_PATH=/home/user/.local/share/QGIS/QGIS3/profiles/default/
export QGIS_SERVER_LOG_FILE=/home/user/qserv.log
export QGIS_SERVER_LOG_LEVEL=2
spawn-fcgi -f /usr/lib/cgi-bin/qgis_mapserv.fcgi -s /tmp/qgisserver.sock -U www-data -G www-data -n

 QGIS Server Settings:

   - QGIS_OPTIONS_PATH / '' (Override the default path for user configuration): '/home/user/.local/share/QGIS/QGIS3/profiles/default/' (read from ENVIRONMENT_VARIABLE)

   - QGIS_SERVER_PARALLEL_RENDERING / '/qgis/parallel_rendering' (Activate/Deactivate parallel rendering for WMS getMap request): 'true' (read from INI_FILE)

   - QGIS_SERVER_MAX_THREADS / '/qgis/max_threads' (Number of threads to use when parallel rendering is activated): '4' (read from INI_FILE)

   - QGIS_SERVER_LOG_LEVEL / '' (Log level): '2' (read from ENVIRONMENT_VARIABLE)

   - QGIS_SERVER_LOG_FILE / '' (Log file): '/tmp/qserv.log' (read from ENVIRONMENT_VARIABLE)

   - QGIS_PROJECT_FILE / '' (QGIS project file): '' (read from DEFAULT_VALUE)

   - MAX_CACHE_LAYERS / '' (Specify the maximum number of cached layers): '100' (read from DEFAULT_VALUE)

   - QGIS_SERVER_CACHE_DIRECTORY / '/cache/directory' (Specify the cache directory): '/root/.local/share/QGIS/QGIS3/profiles/default/cache' (read from DEFAULT_VALUE)

   - QGIS_SERVER_CACHE_SIZE / '/cache/size' (Specify the cache size): '52428800' (read from INI_FILE)

 Ini file used to initialize settings: /home/user/.local/share/QGIS/QGIS3/profiles/default/QGIS/QGIS3.ini

In this particular case, we know that QGIS_SERVER_MAX_THREADS and QGIS_SERVER_PARALLEL_RENDERING values are read from the ini file found in QGIS_OPTIONS_PATH directory (which is defined through an environment variable). The corresponding entries in the ini file are /qgis/max_threads and /qgis/parallel_rendering and their values are true and 4 threads.

레이어, 그룹 및 프로젝트를 위한 약칭

많은 객체가 <Name><Title> 을 보유하고 있습니다. Name 은 사물통신에 쓰이는 텍스트 문자열인 반면 Title 은 사람이 읽고 이해하기 위한 문자열입니다.

예를 들어, 어느 데이터셋이 《최대 기온(Maximum Atmospheric Temperature)》이란 서술적 제목을 보유한 동시에 약칭 “ATMAX”를 사용한 요청을 받을 수도 있습니다. 사용자는 이미 레이어, 그룹 및 프로젝트를 위한 제목을 설정할 수 있습니다.

OWS 명칭은 레이어 트리에서 사용되는 명칭을 기반으로 합니다. 이 명칭은 사물통신을 위한 명칭이라기보다는 사람을 위한 라벨에 더 가깝습니다.

QGIS 서버는 다음을 지원하고 있습니다:

  • 레이어 속성에서 약칭을 편집할 수 있습니다. 레이어를 오른쪽 클릭한 다음 Properties ‣ Metadata tab ‣ Description ‣ Short name 을 선택하면 변경할 수 있습니다.

  • 레이어 트리 그룹의 WMS 데이터 대화창 (약칭, 제목, 요약)

    레이어 그룹을 오른쪽 클릭한 다음 Set Group WMS data 메뉴 옵션을 선택하면 다음 대화창이 열립니다:

    ../../../../_images/set_group_wms_data.png

    그룹 WMS 데이터 대화창 설정하기

  • 프로젝트 속성에서 약칭을 편집할 수 있습니다. 정적 방식(static method)으로 접근할 수 있는 약칭 편집 란에 정규 표현식 유효성 검사 문자(validator) "^[A-Za-z][A-Za-z0-9\._-]*" 를 추가하십시오.

  • 정적 방식(static method)으로 접근할 수 있는 약칭 편집 란에 정규 표현식 유효성 검사 문자(validator) "^[A-Za-z][A-Za-z0-9\._-]*" 를 추가하십시오.

    Project properties ‣ OWS Server ‣ Service capabilities ‣ Short name 메뉴 옵션을 선택하면 프로젝트 루트를 위한 약칭을 선택할 수 있습니다.

  • fullProjectSettingsTreeName 항목을 추가할 수 있습니다.

레이어, 그룹 또는 프로젝트를 위한 약칭을 설정했다면, QGIS 서버가 해당 약칭을 레이어명으로 사용할 것입니다.

서비스 파일에 연결

Apache가 PostgreSQL 서비스 파일(PostgreSQL 서비스 연결 파일 참조)을 인지하도록 하려면, 사용자의 *.conf 파일을 다음과 같이 추가해야 합니다:

SetEnv PGSERVICEFILE /home/web/.pg_service.conf

<Directory "/home/web/apps2/bin/">
  AllowOverride None
.....

사용자 리눅스 서버에 폰트 추가

사용자의 QGIS 프로젝트가 가리키는 폰트가 다른 시스템 상에는 기본적으로 존재하지 않을 수도 있다는 사실을 기억하고 있어야 합니다. 즉 프로젝트를 공유하는 경우, (대상 컴퓨터에 해당 폰트가 없다면) 다른 컴퓨터에서는 다르게 보일 수도 있다는 뜻입니다.

이런 일이 일어나지 않도록 보장하려면, 대상 컴퓨터에 빠진 폰트를 설치하기만 하면 됩니다. 데스크탑 시스템인 경우 보통 이 작업은 어렵지 않습니다. (폰트 파일을 더블클릭하면 됩니다.)

리눅스의 경우, 데스크탑 환경이 설치되지 않았다면 (또는 사용자가 명령 줄 인터페이스를 선호한다면) 다음 명령어를 실행하면 됩니다:

  • 데비안 기반 시스템인 경우:

    sudo su
    mkdir -p /usr/local/share/fonts/truetype/myfonts && cd /usr/local/share/fonts/truetype/myfonts
    
    # copy the fonts from their location
    cp /fonts_location/* .
    
    chown root *
    cd .. && fc-cache -f -v
    
  • 페도라 기반 시스템인 경우:

    sudo su
    mkdir /usr/share/fonts/myfonts && cd /usr/share/fonts/myfonts
    
    # copy the fonts from their location
    cp /fonts_location/* .
    
    chown root *
    cd .. && fc-cache -f -v