18.2.4. 高度な構成

18.2.4.1. ログを作成する

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.

18.2.4.2. 環境変数

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サーバー構成.

名前

説明

Default

サービス

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.

''

All

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=/home/qgis/projects/world.qgs&SERVICE=WMS&REQUEST=GetCapabilities" \
/usr/lib/cgi-bin/qgis_mapserv.fcgi

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

''

All

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.

''

All

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.

''

All

QGIS_SERVER_LOG_STDERR

Activate logging to stderr. This variable has no effect when QGIS_SERVER_LOG_FILE is set.

  • 0 or false (case insensitive)

  • 1 or true (case insensitive)

false

All

MAX_CACHE_LAYERS

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

100

All

QGIS_PLUGINPATH

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

''

All

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)

0

All

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)

false

WMS

QGIS_SERVER_MAX_THREADS

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

-1

All

QGIS_SERVER_CACHE_DIRECTORY

Specifies the network cache directory on the filesystem.

cache in profile directory

All

QGIS_SERVER_CACHE_SIZE

Sets the network cache size in MB.

50 MB

All

QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE

Sets LOCALE to be used by QGIS server. The default value is empty (no override).

Example: de_CH.utf8

''

All

QGIS_SERVER_SHOW_GROUP_SEPARATOR

Defines whether a group separator (e.g. thousand separator) should be used for numeric values (e.g. in GetFeatureInfo responses). The default value is 0.

  • 0 or false (case insensitive)

  • 1 or true (case insensitive)

false

WMS

QGIS_SERVER_IGNORE_BAD_LAYERS

"Bad" layers are layers that cannot be loaded. The default behavior of QGIS Server is to consider the project as not available if it contains a bad layer.

The default behavior can be overridden by setting this variable to 1 or true. In this case, "bad" layers will just be ignored, and the project will be considered valid and available.

false

All

QGIS_SERVER_WMS_MAX_HEIGHT / QGIS_SERVER_WMS_MAX_WIDTH

Maximum height/width for a WMS request. The most conservative between this and the project one is used. If the value is -1, it means that there is no maximum set.

-1

WMS

QGIS_SERVER_API_RESOURCES_DIRECTORY

Base directory for all OGC API (such as OAPIF/WFS3) static resources (HTML templates, CSS, JS, ...)

depends on packaging

WFS

QGIS_SERVER_API_WFS3_MAX_LIMIT

Maximum value for limit in a features request.

10000

WFS

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

18.2.4.4. レイヤー、グループ、およびプロジェクトの短い名前

要素の数は、 <Name><Title> の両方を有します。 は、マシン・ツー・マシンの通信に使用するテキスト文字列で、 タイトル は人間の利益のものです。

For example, a dataset might have the descriptive Title “Maximum Atmospheric Temperature” and be requested using the abbreviated Name “ATMAX”. User can already set title for layers, groups and project.

OWS名はレイヤーツリーに使用される名前に基づいています。この名前は、マシン間通信のための名前よりもより人間のためのラベルです。

QGISサーバーがサポートするのは:

  • レイヤープロパティへの短い名前の行編集 これを変更するには、レイヤーを右クリックして、 プロパティ ▶ [メタデータ]タブ ▶ 説明 ▶ 短い名前 を選択します。

  • レイヤーツリーグループへのWMSデータダイアログ(短い名前、タイトル、要約)

    レイヤーグループを右クリックし、 グループWMS データを設定 オプションを選択すると、次のようになります:

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

    図 18.15 グループWMSデータダイアログを設定する

  • プロジェクトプロパティへの短い名前の行編集 - 静的メソッドを介して短い名前の行編集にアクセス可能な正規表現バリデータ 「^[A-Za-z][A-Za-z0-9\._-]*」 を追加します

  • 静的メソッドを介して短い名前のラインエディットにアクセス可能な正規表現のバリデータ 「^[A-ZA-z][A-ZA-Z0-9\._-]*」 を追加します

    プロジェクトのプロパティ ▶ OWSサーバー ▶ サービスの機能 ▶ 短い名前 の順に選択すると、プロジェクトルートの短い名前を選択できます。

  • fullProjectSettingsTreeName 要素を追加

短い名前がレイヤー、グループやプロジェクトのために設定されている場合には、レイヤー名としてQGISサーバーによって使用されます。

18.2.4.5. サービスファイルへの接続

PostgreSQLのサービス・ファイルのApacheが認識できるようにするために( PGサービスファイル セクションを参照) *.conf ファイルのようなを見て、確認する必要があり:

SetEnv PGSERVICEFILE /home/web/.pg_service.conf

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

18.2.4.6. お使いのLinuxサーバーにフォントを追加

他のマシン上のデフォルトでは存在しないかもしれないフォントを指すQGISプロジェクトを使用するかもしれないことに注意してください。これは、プロジェクトを共有する場合(フォントがターゲットマシン上に存在しない場合)、それは他のマシン上で異なって見える可能性があることを意味します。

これが起こらないようにするために、単にターゲットマシン上で不足しているフォントをインストールする必要があります。デスクトップシステム上でこれを行うのは通常は自明です(フォントをダブルクリック)。

Linuxに対しては、デスクトップ環境をインストールしていない(または、コマンドラインを好む)場合、する必要があります:

  • Debianのベースのシステム:

    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
    
  • Fedoraのベースのシステム:

    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