mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-06-15 12:36:05 +00:00
Move web server config to separate folder.
This commit is contained in:
@ -0,0 +1,181 @@
|
||||
Following is an example showing how to run PowerDNS-Admin with systemd, gunicorn and nginx:
|
||||
|
||||
## Configure PowerDNS-Admin
|
||||
|
||||
Create PowerDNS-Admin config file and make the changes necessary for your use case. Make sure to change `SECRET_KEY` to a long random string that you generated yourself ([see Flask docs](https://flask.palletsprojects.com/en/1.1.x/config/#SECRET_KEY)), do not use the pre-defined one.
|
||||
```
|
||||
$ cp /opt/web/powerdns-admin/configs/development.py /opt/web/powerdns-admin/configs/production.py
|
||||
$ vim /opt/web/powerdns-admin/configs/production.py
|
||||
```
|
||||
|
||||
## Configure systemd service
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.service`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS-Admin
|
||||
Requires=powerdns-admin.socket
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
PIDFile=/run/powerdns-admin/pid
|
||||
User=pdns
|
||||
Group=pdns
|
||||
WorkingDirectory=/opt/web/powerdns-admin
|
||||
ExecStartPre=+mkdir -p /run/powerdns-admin/
|
||||
ExecStartPre=+chown pdns:pdns -R /run/powerdns-admin/
|
||||
ExecStart=/usr/local/bin/gunicorn --pid /run/powerdns-admin/pid --bind unix:/run/powerdns-admin/socket 'powerdnsadmin:create_app()'
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
ExecStop=/bin/kill -s TERM $MAINPID
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
`$ sudo systemctl edit powerdns-admin.service`
|
||||
|
||||
```
|
||||
[Service]
|
||||
Environment="FLASK_CONF=../configs/production.py"
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.socket`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS-Admin socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/powerdns-admin/socket
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/tmpfiles.d/powerdns-admin.conf`
|
||||
|
||||
```
|
||||
d /run/powerdns-admin 0755 pdns pdns -
|
||||
```
|
||||
|
||||
Then `sudo systemctl daemon-reload; sudo systemctl start powerdns-admin.socket; sudo systemctl enable powerdns-admin.socket` to start the Powerdns-Admin service and make it run on boot.
|
||||
|
||||
## Sample nginx configuration
|
||||
```
|
||||
server {
|
||||
listen *:80;
|
||||
server_name powerdns-admin.local www.powerdns-admin.local;
|
||||
|
||||
index index.html index.htm index.php;
|
||||
root /opt/web/powerdns-admin;
|
||||
access_log /var/log/nginx/powerdns-admin.local.access.log combined;
|
||||
error_log /var/log/nginx/powerdns-admin.local.error.log;
|
||||
|
||||
client_max_body_size 10m;
|
||||
client_body_buffer_size 128k;
|
||||
proxy_redirect off;
|
||||
proxy_connect_timeout 90;
|
||||
proxy_send_timeout 90;
|
||||
proxy_read_timeout 90;
|
||||
proxy_buffers 32 4k;
|
||||
proxy_buffer_size 8k;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_headers_hash_bucket_size 64;
|
||||
|
||||
location ~ ^/static/ {
|
||||
include /etc/nginx/mime.types;
|
||||
root /opt/web/powerdns-admin/powerdnsadmin;
|
||||
|
||||
location ~* \.(jpg|jpeg|png|gif)$ {
|
||||
expires 365d;
|
||||
}
|
||||
|
||||
location ~* ^.+.(css|js)$ {
|
||||
expires 7d;
|
||||
}
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://unix:/run/powerdns-admin/socket;
|
||||
proxy_read_timeout 120;
|
||||
proxy_connect_timeout 120;
|
||||
proxy_redirect off;
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Sample Nginx-Configuration for SSL</summary>
|
||||
|
||||
* Im binding this config to every dns-name with default_server...
|
||||
* but you can remove it and set your server_name.
|
||||
|
||||
```
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name "";
|
||||
return 301 https://$http_host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2 default_server;
|
||||
server_name _;
|
||||
index index.html index.htm;
|
||||
error_log /var/log/nginx/error_powerdnsadmin.log error;
|
||||
access_log off;
|
||||
|
||||
ssl_certificate path_to_your_fullchain_or_cert;
|
||||
ssl_certificate_key path_to_your_key;
|
||||
ssl_dhparam path_to_your_dhparam.pem;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
|
||||
client_max_body_size 10m;
|
||||
client_body_buffer_size 128k;
|
||||
proxy_redirect off;
|
||||
proxy_connect_timeout 90;
|
||||
proxy_send_timeout 90;
|
||||
proxy_read_timeout 90;
|
||||
proxy_buffers 32 4k;
|
||||
proxy_buffer_size 8k;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_headers_hash_bucket_size 64;
|
||||
|
||||
location ~ ^/static/ {
|
||||
include mime.types;
|
||||
root /opt/web/powerdns-admin/powerdnsadmin;
|
||||
location ~* \.(jpg|jpeg|png|gif)$ { expires 365d; }
|
||||
location ~* ^.+.(css|js)$ { expires 7d; }
|
||||
}
|
||||
|
||||
location ~ ^/upload/ {
|
||||
include mime.types;
|
||||
root /opt/web/powerdns-admin;
|
||||
location ~* \.(jpg|jpeg|png|gif)$ { expires 365d; }
|
||||
location ~* ^.+.(css|js)$ { expires 7d; }
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://unix:/run/powerdns-admin/socket;
|
||||
proxy_read_timeout 120;
|
||||
proxy_connect_timeout 120;
|
||||
proxy_redirect http:// $scheme://;
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
## Note
|
||||
* `/opt/web/powerdns-admin` is the path to your powerdns-admin web directory
|
||||
* Make sure you have installed gunicorn in flask virtualenv already.
|
||||
* `powerdns-admin.local` just an example of your web domain name.
|
@ -0,0 +1,97 @@
|
||||
Following is an example showing how to run PowerDNS-Admin with systemd, gunicorn and Apache:
|
||||
|
||||
The systemd and gunicorn setup are the same as for with nginx. This set of configurations assumes you have installed your PowerDNS-Admin under /opt/powerdns-admin and are running with a package-installed gunicorn.
|
||||
|
||||
## Configure systemd service
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.service`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS web administration service
|
||||
Requires=powerdns-admin.socket
|
||||
Wants=network.target
|
||||
After=network.target mysqld.service postgresql.service slapd.service mariadb.service
|
||||
|
||||
[Service]
|
||||
PIDFile=/run/powerdns-admin/pid
|
||||
User=pdnsa
|
||||
Group=pdnsa
|
||||
WorkingDirectory=/opt/powerdns-admin
|
||||
ExecStart=/usr/bin/gunicorn-3.6 --workers 4 --log-level info --pid /run/powerdns-admin/pid --bind unix:/run/powerdns-admin/socket "powerdnsadmin:create_app(config='config.py')"
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
ExecStop=/bin/kill -s TERM $MAINPID
|
||||
PrivateTmp=true
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
StartLimitInterval=0
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.socket`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS-Admin socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/powerdns-admin/socket
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/tmpfiles.d/powerdns-admin.conf`
|
||||
|
||||
```
|
||||
d /run/powerdns-admin 0755 pdnsa pdnsa -
|
||||
```
|
||||
|
||||
Then `sudo systemctl daemon-reload; sudo systemctl start powerdns-admin.socket; sudo systemctl enable powerdns-admin.socket` to start the Powerdns-Admin service and make it run on boot.
|
||||
|
||||
## Sample Apache configuration
|
||||
|
||||
This includes SSL redirect.
|
||||
|
||||
```
|
||||
<VirtualHost *:80>
|
||||
ServerName dnsadmin.company.com
|
||||
DocumentRoot "/opt/powerdns-admin"
|
||||
<Directory "/opt/powerdns-admin">
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
Redirect permanent / https://dnsadmin.company.com/
|
||||
</VirtualHost>
|
||||
<VirtualHost *:443>
|
||||
ServerName dnsadmin.company.com
|
||||
DocumentRoot "/opt/powerdns-admin/powerdnsadmin"
|
||||
## Alias declarations for resources outside the DocumentRoot
|
||||
Alias /static/ "/opt/powerdns-admin/powerdnsadmin/static/"
|
||||
Alias /favicon.ico "/opt/powerdns-admin/powerdnsadmin/static/favicon.ico"
|
||||
<Directory "/opt/powerdns-admin">
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
## Proxy rules
|
||||
ProxyRequests Off
|
||||
ProxyPreserveHost On
|
||||
ProxyPass /static/ !
|
||||
ProxyPass /favicon.ico !
|
||||
ProxyPass / unix:/var/run/powerdns-admin/socket|http://%{HTTP_HOST}/
|
||||
ProxyPassReverse / unix:/var/run/powerdns-admin/socket|http://%{HTTP_HOST}/
|
||||
## SSL directives
|
||||
SSLEngine on
|
||||
SSLCertificateFile "/etc/pki/tls/certs/dnsadmin.company.com.crt"
|
||||
SSLCertificateKeyFile "/etc/pki/tls/private/dnsadmin.company.com.key"
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
## Notes
|
||||
* The above assumes your installation is under /opt/powerdns-admin
|
||||
* The hostname is assumed as dnsadmin.company.com
|
||||
* gunicorn is installed in /usr/bin via a package (as in the case with CentOS/Redhat 7) and you have Python 3.6 installed. If you prefer to use flask then see the systemd configuration for nginx.
|
||||
* On Ubuntu / Debian systems, you may need to enable the "proxy_http" module with `a2enmod proxy_http`
|
18
docs/wiki/web-server/Supervisord-example.md
Normal file
18
docs/wiki/web-server/Supervisord-example.md
Normal file
@ -0,0 +1,18 @@
|
||||
Following is an example showing how to run PowerDNS-Admin with supervisord
|
||||
|
||||
Create supervisord program config file
|
||||
```
|
||||
$ sudo vim /etc/supervisor.d/powerdnsadmin.conf
|
||||
```
|
||||
|
||||
```
|
||||
[program:powerdnsadmin]
|
||||
command=/opt/web/powerdns-admin/flask/bin/python ./run.py
|
||||
stdout_logfile=/var/log/supervisor/program_powerdnsadmin.log
|
||||
stderr_logfile=/var/log/supervisor/program_powerdnsadmin.error
|
||||
autostart=true
|
||||
autorestart=true
|
||||
directory=/opt/web/powerdns-admin
|
||||
```
|
||||
|
||||
Then `sudo supervisorctl start powerdnsadmin` to start the Powerdns-Admin service.
|
50
docs/wiki/web-server/Systemd-example.md
Normal file
50
docs/wiki/web-server/Systemd-example.md
Normal file
@ -0,0 +1,50 @@
|
||||
## Configure systemd service
|
||||
|
||||
This example uses package-installed gunicorn (instead of flask-installed) and PowerDNS-Admin installed under /opt/powerdns-admin
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.service`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS web administration service
|
||||
Requires=powerdns-admin.socket
|
||||
Wants=network.target
|
||||
After=network.target mysqld.service postgresql.service slapd.service mariadb.service
|
||||
|
||||
[Service]
|
||||
PIDFile=/run/powerdns-admin/pid
|
||||
User=pdnsa
|
||||
Group=pdnsa
|
||||
WorkingDirectory=/opt/powerdns-admin
|
||||
ExecStart=/usr/bin/gunicorn-3.6 --workers 4 --log-level info --pid /run/powerdns-admin/pid --bind unix:/run/powerdns-admin/socket "powerdnsadmin:create_app(config='config.py')"
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
ExecStop=/bin/kill -s TERM $MAINPID
|
||||
PrivateTmp=true
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
StartLimitInterval=0
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/systemd/system/powerdns-admin.socket`
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=PowerDNS-Admin socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/powerdns-admin/socket
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
```
|
||||
|
||||
`$ sudo vim /etc/tmpfiles.d/powerdns-admin.conf`
|
||||
|
||||
```
|
||||
d /run/powerdns-admin 0755 pdns pdns -
|
||||
```
|
||||
|
||||
Then `sudo systemctl daemon-reload; sudo systemctl start powerdns-admin.socket; sudo systemctl enable powerdns-admin.socket` to start the Powerdns-Admin service and make it run on boot.
|
100
docs/wiki/web-server/WSGI-Apache-example.md
Normal file
100
docs/wiki/web-server/WSGI-Apache-example.md
Normal file
@ -0,0 +1,100 @@
|
||||
How to run PowerDNS-Admin via WSGI and Apache2.4 using mod_wsgi.
|
||||
|
||||
**Note**: You must install mod_wsgi by using pip3 instead of system default mod_wsgi!!!
|
||||
|
||||
### Ubuntu/Debian
|
||||
```shell
|
||||
# apt install apache2-dev
|
||||
# virtualenv -p python3 flask
|
||||
# source ./flask/bin/activate
|
||||
(flask) # pip3 install mod-wsgi
|
||||
(flask) # mod_wsgi-express install-module > /etc/apache2/mods-available/wsgi.load
|
||||
(flask) # a2enmod wsgi
|
||||
(flask) # systemctl restart apache2
|
||||
```
|
||||
### CentOS
|
||||
```shell
|
||||
# yum install httpd-devel
|
||||
# virtualenv -p python3 flask
|
||||
# source ./flask/bin/activate
|
||||
(flask) # pip3 install mod-wsgi
|
||||
(flask) # mod_wsgi-express install-module > /etc/httpd/conf.modules.d/02-wsgi.conf
|
||||
(flask) # systemctl restart httpd
|
||||
```
|
||||
### Fedora
|
||||
```bash
|
||||
# Install Apache's Development interfaces and package requirements
|
||||
dnf install httpd-devel gcc gc make
|
||||
virtualenv -p python3 flask
|
||||
source ./flask/bin/activate
|
||||
# Install WSGI for HTTPD
|
||||
pip install mod_wsgi-httpd
|
||||
# Install WSGI
|
||||
pip install mod-wsgi
|
||||
# Enable the module in Apache:
|
||||
mod_wsgi-express install-module > /etc/httpd/conf.modules.d/02-wsgi.conf
|
||||
systemctl restart httpd
|
||||
```
|
||||
|
||||
Apache vhost configuration;
|
||||
```apache
|
||||
<VirtualHost *:443>
|
||||
ServerName superawesomedns.foo.bar
|
||||
ServerAlias [fe80::1]
|
||||
ServerAdmin webmaster@foo.bar
|
||||
|
||||
SSLEngine On
|
||||
SSLCertificateFile /some/path/ssl/certs/cert.pem
|
||||
SSLCertificateKeyFile /some/path/ssl/private/cert.key
|
||||
|
||||
ErrorLog /var/log/apache2/error-superawesomedns.foo.bar.log
|
||||
CustomLog /var/log/apache2/access-superawesomedns.foo.bar.log combined
|
||||
|
||||
DocumentRoot /srv/vhosts/superawesomedns.foo.bar/
|
||||
|
||||
WSGIDaemonProcess pdnsadmin user=pdnsadmin group=pdnsadmin threads=5
|
||||
WSGIScriptAlias / /srv/vhosts/superawesomedns.foo.bar/powerdnsadmin.wsgi
|
||||
|
||||
# pass BasicAuth on to the WSGI process
|
||||
WSGIPassAuthorization On
|
||||
|
||||
<Directory "/srv/vhosts/superawesomedns.foo.bar/">
|
||||
WSGIProcessGroup pdnsadmin
|
||||
WSGIApplicationGroup %{GLOBAL}
|
||||
|
||||
AllowOverride None
|
||||
Options +ExecCGI +FollowSymLinks
|
||||
SSLRequireSSL
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
```
|
||||
**In Fedora, you might want to change the following line:**
|
||||
```apache
|
||||
WSGIDaemonProcess pdnsadmin socket-user=apache user=pdnsadmin group=pdnsadmin threads=5
|
||||
```
|
||||
**And you should add the following line to `/etc/httpd/conf/httpd.conf`:**
|
||||
```apache
|
||||
WSGISocketPrefix /var/run/wsgi
|
||||
```
|
||||
|
||||
Content of `/srv/vhosts/superawesomedns.foo.bar/powerdnsadmin.wsgi`;
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
sys.path.insert(0, '/srv/vhosts/superawesomedns.foo.bar')
|
||||
|
||||
from app import app as application
|
||||
```
|
||||
Starting from 0.2 version, the `powerdnsadmin.wsgi` file is slighty different :
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
sys.path.insert(0, '/srv/vhosts/superawesomedns.foo.bar')
|
||||
|
||||
from powerdnsadmin import create_app
|
||||
application = create_app()
|
||||
```
|
||||
|
||||
(this implies that the pdnsadmin user/group exists, and that you have mod_wsgi loaded)
|
49
docs/wiki/web-server/uWSGI-example.md
Normal file
49
docs/wiki/web-server/uWSGI-example.md
Normal file
@ -0,0 +1,49 @@
|
||||
This guide will show you how to run PowerDNS-Admin via uWSGI and nginx. This guide was written using Debian 8 with the following software versions:
|
||||
- nginx 1.6.2
|
||||
- uwsgi 2.0.7-debian
|
||||
- python 2.7.9
|
||||
|
||||
`sudo apt-get install uwsgi uwsgi-plugin-python nginx`
|
||||
|
||||
### Step-by-step instructions
|
||||
1. Create a uWSGI .ini in `/etc/uwsgi/apps-enabled` with the following contents, making sure to replace the chdir, pythonpath and virtualenv directories with where you've installed PowerDNS-Admin:
|
||||
```ini
|
||||
[uwsgi]
|
||||
plugins = python27
|
||||
|
||||
uid=www-data
|
||||
gid=www-data
|
||||
|
||||
chdir = /opt/pdns-admin/PowerDNS-Admin/
|
||||
pythonpath = /opt/pdns-admin/PowerDNS-Admin/
|
||||
virtualenv = /opt/pdns-admin/PowerDNS-Admin/flask
|
||||
|
||||
mount = /pdns=powerdnsadmin:create_app()
|
||||
manage-script-name = true
|
||||
|
||||
vacuum = true
|
||||
harakiri = 20
|
||||
buffer-size = 32768
|
||||
post-buffering = 8192
|
||||
socket = /run/uwsgi/app/%n/%n.socket
|
||||
chown-socket = www-data
|
||||
pidfile = /run/uwsgi/app/%n/%n.pid
|
||||
|
||||
daemonize = /var/log/uwsgi/app/%n.log
|
||||
enable-threads
|
||||
```
|
||||
2. Add the following configuration to your nginx config:
|
||||
```nginx
|
||||
location / { try_files $uri @pdns_admin; }
|
||||
|
||||
location @pdns_admin {
|
||||
include uwsgi_params;
|
||||
uwsgi_pass unix:/run/uwsgi/app/pdns-admin/pdns-admin.socket;
|
||||
}
|
||||
|
||||
location /pdns/static/ {
|
||||
alias /opt/pdns-admin/PowerDNS-Admin/app/static/;
|
||||
}
|
||||
```
|
||||
3. Restart nginx and uwsgi.
|
||||
4. You're done and PowerDNS-Admin will now be available via nginx.
|
Reference in New Issue
Block a user