Outdated version of the documentation. Find the latest one here.

시작하기

Installation

At this point, we will give a short and simple sample installation how-to for a minimal working configuration using Apache2 on Debian/Ubuntu. The first step is QGIS Server installation whose instructions are provided in QGIS installers page.

HTTP 서버 환경 설정

Apache

개별 가상 호스트에 Apache 서버를 80 포트에서 수신하도록 설치하십시오. HTTP BASIC 인증 헤더를 전송할 수 있도록 재작성 모듈을 다음과 같이 활성화하십시오:

$ sudo a2enmod rewrite
$ cat /etc/apache2/conf-available/qgis-server-port.conf
Listen 80
$ sudo a2enconf qgis-server-port

다음은 /etc/apache2/sites-available/001-qgis-server.conf 파일에 저장된 가상 호스트 환경 설정입니다:

<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/html

 ErrorLog ${APACHE_LOG_DIR}/qgis-server-error.log
 CustomLog ${APACHE_LOG_DIR}/qgis-server-access.log combined

 # Longer timeout for WPS... default = 40
 FcgidIOTimeout 120
 FcgidInitialEnv LC_ALL "en_US.UTF-8"
 FcgidInitialEnv PYTHONIOENCODING UTF-8
 FcgidInitialEnv LANG "en_US.UTF-8"
 FcgidInitialEnv QGIS_DEBUG 1
 FcgidInitialEnv QGIS_SERVER_LOG_FILE /tmp/qgis-000.log
 FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
     AllowOverride All
     Options +ExecCGI -MultiViews +FollowSymLinks
     # for apache2 > 2.4
     Require all granted
     #Allow from all
 </Directory>
</VirtualHost>

이제 다음과 같이 가상 호스트를 활성화한 다음 Apache를 재시작하십시오:

$ sudo a2ensite 001-qgis-server
$ sudo service apache2 restart

Nginx

You can use QGIS Server with nginx.

On Debian based systems:

apt-get install nginx fcgiwrap

Introduce the following in your nginx server block configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  location ~ ^/cgi-bin/.*\.fcgi$ {
      gzip           off;
      include fastcgi_params;
      fastcgi_pass   unix:/var/run/fcgiwrap.socket;

      fastcgi_param  SCRIPT_FILENAME /usr/lib/cgi-bin/qgis_mapserv.fcgi;
      fastcgi_param  QGIS_SERVER_LOG_FILE /logs/qgisserver.log;
      fastcgi_param  QGIS_SERVER_LOG_LEVEL 0;
      fastcgi_param  QGIS_DEBUG 1;
  }

As you can see from lines 6-9 you can add parameters in your location block in the form of fastcgi_param param_name param_value, e.g. fastcgi_param  DISPLAY ":99";.

The include fastcgi_params; is important as it adds the parameters from /etc/nginx/fastcgi_params:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Prepare a project to serve

To provide a new QGIS Server WMS, WFS or WCS, we have to create a QGIS project file with some data. Here, we use the ‘Alaska’ shapefile from the QGIS sample dataset. Define the colors and styles of the layers in QGIS and the project CRS, if not already defined.

../../../../_images/ows_server_definition.png

WMS/WFS/WCS를 서비스하는 QGIS 서버 프로젝트 정의하기

Then, go to the OWS Server menu of the Project ‣ Project Properties dialog and provide some information about the OWS in the fields under Service Capabilities. This will appear in the GetCapabilities response of the WMS, WFS or WCS. If you don’t check checkbox Service capabilities, QGIS Server will use the information given in the wms_metadata.xml file located in the cgi-bin folder.

경고

If you’re using the QGIS project with styling based on SVG files using relative paths then you should know that the server considers the path relative to its qgis_mapserv.fcgi file (not to the qgs file). So, if you deploy a project on the server and the SVG files are not placed accordingly, the output images may not respect the Desktop styling. To ensure this doesn’t happen, you can simply copy the SVG files relative to the qgis_mapserv.fcgi. You can also create a symbolic link in the directory where the fcgi file resides that points to the directory containing the SVG files (on Linux/Unix).

WMS 능력

In the WMS capabilities section, you can define the extent advertised in the WMS GetCapabilities response by entering the minimum and maximum X and Y values in the fields under Advertised extent. Clicking Use Current Canvas Extent sets these values to the extent currently displayed in the QGIS map canvas. By checking checkbox CRS restrictions, you can restrict in which coordinate reference systems (CRS) QGIS Server will offer to render maps. Use the signPlus button below to select those CRSs from the Coordinate Reference System Selector, or click Used to add the CRSs used in the QGIS project to the list.

If you have print composers defined in your project, they will be listed in the GetProjectSettings response, and they can be used by the GetPrint request to create prints, using one of the print composer layouts as a template. This is a QGIS-specific extension to the WMS 1.3.0 specification. If you want to exclude any print composer from being published by the WMS, check checkbox Exclude composers and click the signPlus button below. Then, select a print composer from the Select print composer dialog in order to add it to the excluded composers list.

If you want to exclude any layer or layer group from being published by the WMS, check checkbox Exclude Layers and click the signPlus button below. This opens the Select restricted layers and groups dialog, which allows you to choose the layers and groups that you don’t want to be published. Use the Shift or Ctrl key if you want to select multiple entries.

요청한 GetFeatureInfo 를 평문 텍스트, XML 및 GML로 받을 수 있습니다. 기본값은 XML이며, GetFeatureInfo 요청에 대해 선택한 출력 포맷에 따라 텍스트 또는 GML 포맷으로 받을 수 있습니다.

If you wish, you can check checkbox Add geometry to feature response. This will include in the GetFeatureInfo response the geometries of the features in a text format. If you want QGIS Server to advertise specific request URLs in the WMS GetCapabilities response, enter the corresponding URL in the Advertised URL field. Furthermore, you can restrict the maximum size of the maps returned by the GetMap request by entering the maximum width and height into the respective fields under Maximums for GetMap request.

사용자 레이어 가운데 하나가 맵 도움말 표시 를 이용하고 있는 경우 (예: 표현식을 사용해서 텍스트를 표시하는 경우) GetFeatureInfo 출력물 안에 이 정보가 들어 있을 것입니다. 레이어가 값 맵(개념 매핑)을 이용하고 있다면, 이 정보도 GetFeatureInfo 출력물 안에 들어 있을 것입니다.

WFS 능력

WFS capabilities 부분에서 사용자가 WFS로 게시하려는 레이어를 선택할 수 있고, 해당 레이어를 업데이트, 삽입 및 삭제할 수 있는지 설정할 수 있습니다. WFS capabilities 부분의 Advertised URL 란에 URL을 입력한다면, QGIS 서버가 WFS GetCapabilities 응답에 이 특정 URL을 선언할 것입니다.

WCS 능력

WCS capabilities 부분에서 사용자가 WCS로 게시하려는 레이어를 선택할 수 있습니다. WCS capabilities 부분의 Advertised URL 란에 URL을 입력한다면, QGIS 서버가 WCS GetCapabilities 응답에 이 특정 URL을 선언할 것입니다.

사용자 OWS를 미세 조정하기

벡터 레이어의 경우, Layer ‣ Properties 대화창의 Fields 탭에서 각 속성을 게시할 것인지 여부를 정의할 수 있습니다. 기본적으로, 사용자의 WMS 및 WFS는 모든 속성을 게시합니다. 특정 속성을 게시하고 싶지 않은 경우, WMS 또는 WFS 열에서 해당하는 체크박스를 체크 해제하십시오.

You can overlay watermarks over the maps produced by your WMS by adding text annotations or SVG annotations to the project file. See the 주석 도구 section for instructions on creating annotations. For annotations to be displayed as watermarks on the WMS output, the Fixed map position checkbox in the Annotation text dialog must be unchecked. This can be accessed by double clicking the annotation while one of the annotation tools is active. For SVG annotations, you will need either to set the project to save absolute paths (in the General menu of the Project ‣ Project Properties dialog) or to manually modify the path to the SVG image so that it represents a valid relative path.

Serve the project

Now, save the session in a project file alaska.qgs. To provide the project as a WMS/WFS, create a new folder /usr/lib/cgi-bin/project with admin privileges and add the project file alaska.qgs and a copy of the qgis_mapserv.fcgi file - that’s all.

Now test your project WMS, WFS and WCS. Add the WMS, WFS and WCS as described in WMS/WMTS 레이어 불러오기, WFS 및 WFS-T 클라이언트 and WCS 클라이언트 to QGIS and load the data. The URL is:

http://localhost/cgi-bin/project/qgis_mapserv.fcgi

Cascading OGC layers

A QGIS project can of course contain layers coming from remote OGC servers (regardless of the underlying OGC server software used). This way QGIS will effectively cascade those layers through its OGC (QGIS Server based) services.

If the external OGC layers are coming from services that make use of the HTTPS protocol you must take care of some extra QGIS Server configuration. Example for the Apache web server:

$ mkdir /srv/qgis/.qgis2
$ chown www-data:www-data /srv/qgis/.qgis2
$ chmod 774 /srv/qgis/.qgis2

This ensures that the web server is able to write in some user defined folder. Then add the following line to the Apache virtual host file to ensure that Apache will use such folder:

FcgidInitialEnv HOME "/srv/qgis"

Restart Apache.