summaryrefslogtreecommitdiffstats
path: root/doc/src/deployment-server-http-server-setup.qdoc
blob: d31b72c0cbbb31e7c700624be9e4b67e52d88aa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/****************************************************************************
**
** Copyright (C) 2019 Luxoft Sweden AB
** Copyright (C) 2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Auto Deployment Server.
**
** $QT_BEGIN_LICENSE:FDL-QTAS$
** Commercial License Usage
** Licensees holding valid commercial Qt Automotive Suite licenses may use
** this file in accordance with the commercial license agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and The Qt Company.  For
** licensing terms and conditions see https://www.qt.io/terms-conditions.
** For further information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \ingroup qtauto-deployment-server
    \page http-server-setup.html
    \previouspage Qt Automotive Suite Deployment Server API Reference
    \nextpage Upload Packages to the Deployment Server
    \startpage Qt Automotive Suite Deployment Server

    \title Set up a Production server with Apache, Lighttpd or Nginx

The Deployment Server can be set up in combination with a regular web server: Apache, Lighttpd, or
 Nginx. This web server can be used to reduce the number of open ports or to add a layer of SSL
 encryption.

There are two possible setups for running with another web server in the Django version used for
the Deployment Server:
\list
  \li reverse proxy setup - which we describe here
  \li WSGI setup - for brevity, this setup is left out of scope, as it is similar in functionality
      to reverse proxy setup
\endlist

\section1 Reverse Proxy Setup

For all web servers, the preliminary setup is the same. First, the deployment server should be set
 up in the same way as for standalone use. If the server will be used in a subdirectory of the
 web server (like http://hostname.domain/url_prefix/ ), then this prefix should be set up in
 \e{appstore/settings.py}, in a \c{URL_PREFIX} variable.

In this example, this variable is set to 'url_prefix'; note the lack of slashes. Also, if
 \c{URL_PREFIX} is set to a non-empty value, \c{STATIC_URL} should be changed too, to start from
 set prefix. So \c{STATIC_URL} would be \c{'/<url_prefix>/static/'} instead of \c{'/static/'}

After that, the server should be set up to run as a service, on any free port.
This is done by running:
\code
  ./venv/bin/python manage.py runserver 127.0.0.1:<port>
\endcode
Assuming that the Python virtual environment was set up in the project directory, under the
 \e{venv} subdirectory.

On Linix and Unix systems, to run as a non-root user, you must use a port number larger than 1024.

Once the service is running, set up the web server's configuration.

\section2 Apache2 Setup

First, enable \b{mod_proxy} and \b{mod_proxy_http} modules in Apache, by running
\c{a2enmod proxy proxy_http}.

Then insert this code snippet into the VirtualHost section of your configuration file:

\code
    <Location '/<url_prefix>/'>
            ProxyPass "http://127.0.0.1:<port>/<url_prefix>/"
            ProxyPassReverse "http://127.0.0.1:<port>/<url_prefix>/"
    </Location>
\endcode

If necessary, add configuration section to set up access permissions to this URL.

After setting this up, reload web server's configuration.

\section2 Lighttpd Setup

For Lighttpd, first, enable mod_proxy, by running \c{lighttpd-enable-mod proxy} as root.
Alternatively, add the following line in your \e{/etc/lighttpd/lighttpd.conf} file:
\code
server.modules   += ( "mod_proxy" )
\endcode

Next, add the following code snippet:
\code
$HTTP["url"] =~ "^/<url_prefix>/" {
      proxy.balance = "hash"
      proxy.server  = ( "" => ( ( "host" => "127.0.0.1", "port" => "<port>" ),
                              ) )
}

\endcode

Where \e{<url_prefix>} is the same as in \e{settings.py} file, and \e{<port>} is the port on which the
Deployment Server instance is running.

Finally, reload the Lighttpd server's configuration.

\section2 Nginx Setup

For Nginx, setup consists of adding a code snippet into server configuration, inside of a
\c{server { } } statement and restarting the server.

The code that needs to be added is:
\code
    location /<url_prefix>/ {
        proxy_pass http://127.0.0.1:<port>/<url_prefix>/;
    }
\endcode

Where \e{<url_prefix>} is the same as in \e{settings.py} file, and \e{<port>} is the port on which the
Deployment Server instance is running.

\section1 Serving Static Files Outside of Django App

It is possible to speed up working of the admin pages of the Deployment Server by serving static files
separately. In order to achieve that, web server should be configured to serve \e{static/} subdirectory of
the Deployment Server installation as \e{static/} subdirectory of the instance. (If the Deployment Server is
hosted as \e{http://deployment.server.name/}, then \e{static/} directory in the sources should be redirected
to \e{http://deployment.server.name/static/}, while bypassing the django app.)

After configuring that, static files collection should be performed using the following command:

\code
  ./venv/bin/python manage.py collect static
\endcode

\section1 Serving static files outside of django app

It is possible to speed up working of the admin pages of deployment server by serving static files
separately. In order to achieve that, webserver should be configured to serve \e{static/} subdirectory of
deployment server installation as \e{static/} subdirectory of the instance. (If deployment server is
hosted as \e{http://deployment.server.name/}, then \e{static/} directory in the sources should be redirected
to \e{http://deployment.server.name/static/}, while bypassing the django app.)

After configuring that, static files collection should be performed with this command:

\code
  ./venv/bin/python manage.py collect static
\endcode

*/