WordPress Installation auf Synology NAS

WordPress Security

Läuft WordPress auf einem Apache Server, dann steuert die .htaccess Datei im jeweiligen Verzeichnis Schreib-/Leserechte und einiges mehr. Nginx unterstützt keine .htaccess Dateien, um keine Performance durch das Lesen dieser zu verlieren. Daher müssen entsprechende Einstellungen in der nginx Konfiguration vorgenommen werden.

nginx konfigurieren

Für ein einfaches Backup, wollen wir die notwendigen Erweiterungen der nginx Konfiguration in unserem etc Verzeichnis ablegen. Hierzu erzeugen wir ein weiteres nginx Unterverzeichnis und legen mit vi eine neue Datei ‚user.conf.d‘ an:

$ cd /volume1/vhosts/test_allius_de/etc/
$ mkdir nginx
$ cd nginx
$ vi user.conf.d

Wir fügen den nachfolgenden Code in die user.conf.d Datei ein und setzen damit erste HTTP Security-Header, verbieten den Zugriff auf kritische Dateien und unterstützen die WordPress Permalinks, indem wir die Zugriffe mittels des try_files Kommandos entsprechend umleiten:

# set some security headers for http responses
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "0" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security max-age=15768000 always;

# redirect unsecure http requests on port 443 like
# http://demo.allius.de:443/ to our https site
error_page 497 =301  https://demo.allius.de$request_uri;


location = /favicon.ico {
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    log_not_found off;
    access_log off;
    add_header  Content-Type  text/plain;
    add_header  Strict-Transport-Security max-age=15768000;
# uncomment next line for the experimental sites
    return 200 "User-agent: *\nDisallow: /\n";
# uncomment next line for the production site
#    return 200 "User-agent: *\nAllow: /\nSitemap: https://demo.allius.de/sitemap.xml\n";
}

# Deny access to readmy.html and liesmich.html in the wordpress directory
location ~ ^/wordpress/(readme|liesmich)\.html$ {
    deny all;
}

# Deny access to wp-config in the wordpress directory
location ~ ^/wordpress/wp-config.php$ {
    deny all;
}

# Deny all attemps to hidden files such as .htaccess, .htpasswd, ..
location ~ /\. {
    deny all;
}

# Deny access to any files with a .php extension in the uploads
# directory for the single site
location ~ ^/app/uploads/.*\.php$ {
    deny all;
}

# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using
# query string
location / {
     try_files $uri $uri/ /index.php?$args;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
     expires max;
     log_not_found off;
}

Damit unsere Einstellungen wirksam werden müssen wir noch einen Symlink in dem Verzeichnis unseres vHosts setzen. Um den passenden Pfad festzustellen, starten wir folgendes Kommando:

$ cat /var/packages/WebStation/etc/VirtualHost.json
$

Nachfolgend habe ich eine möglich Ausgabe abgebildet:

{
   "e4fbe7fa-b229-4ce1-84c5-5b4ebd6201a0" : {
      "backend" : 0,
      "fqdn" : "demo.allius.de",
      "https" : {
         "compatibility" : 1,
         "compression" : false,
         "hsts" : true,
         "http2" : true,
         "redirect" : false
      },
      "index" : [ "index.html", "index.htm", "index.cgi", "index.php", "index.php5" ],
      "php" : "46a4c4d9-8dc1-4b69-849f-1013184a7a76",
      "port" : {
         "http" : [ 80 ],
         "https" : [ 443 ]
      },
      "root" : "/volume1/vhost_demo/demo_allius_de/www"
   },
   "version" : 2
}

In der Ausgabe suchen wir die Zeile „fqdn“ : „demo.allius.de“ und haben damit den Block für unseren vHost gefunden. Vor der öffnenden geschweiften Klammer finden wir in Anführungszeichen den Schlüssel e4fbe7fa-b229-4ce1-84c5-5b4ebd6201a0. Mit dieser Information können wir den symbolischen Link anlegen:

$ cd /usr/local/etc/nginx/conf.d/e4fbe7fa-b229-4ce1-84c5-5b4ebd6201a0
$ ln -s /volume1/vhosts/demo_allius_de/etc/nginx/user.conf.d user.conf.d
$ 

Jetzt kontrollieren wir, ob unsere Konfig fehlerfrei in die nginx Konfiguration eingebunden ist (nginx -T) und starten nginx neu:

$ nginx -T
$ nginx -s reload
$