ubuntuusers.de

Wordpress absichern - php.conf?

Status: Ungelöst | Ubuntu-Version: Server 17.10 (Artful Aardvark)
Antworten |

Nur-Ein-Blogger

Anmeldungsdatum:
4. April 2011

Beiträge: 146

Hallo ihr lieben.

Ich muss mich leider an euch wenden und ist mir etwas unangenehm. Lider fand ich bei Königin Mutter Google keine Antworten auf meine Fragen... https://gist.github.com/eamon55/b83315bb29b1d79a83d0fd66ff3394df

Das da oben ist eine conf für nginx um Wordpress sicherer zu machen. Aber was zum Teufel soll eine php.conf sein und was sollte oder soll drinnen stehen?

ann mir bitte jemand einen Rat geben?

LG

sebix Team-Icon

Ehemalige

Anmeldungsdatum:
14. April 2009

Beiträge: 5584

Das ist eine weitere nginx-Konfigurationsdatei, die eingebunden wird.

Nur-Ein-Blogger

(Themenstarter)

Anmeldungsdatum:
4. April 2011

Beiträge: 146

ah okay. Aber dann besteht das Problem, dass es diese Datei gar nicht gibt. Mit Google finde ich da auch nichts brauchbares. Die File wird in diesem Beispiel eingebunden aber ich weiß ja auch gar nicht was da drinnen stehen sollte.

Bei mir auf dem Server habe ich die Datei nicht gefunden :/

LG

TheDarkRose

Avatar von TheDarkRose

Anmeldungsdatum:
28. Juli 2010

Beiträge: 3459

Da wird wahrscheinlich der php-fpm upstream konfiguriert sein..

frostschutz

Avatar von frostschutz

Anmeldungsdatum:
18. November 2010

Beiträge: 7790

Ziemlich gruseliges Zeugs.


https://codex.wordpress.org/Nginx oder https://wiki.nginx.org/wordpress

Das wichtigste ist dabei in einem Kommentar versteckt:

# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

Wobei ich es vorziehe, zusätzlich auch in nginx zu prüfen, ob die PHP Datei überhaupt existiert.

So ähnlich wie hier: https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

Denn sonst kann man jede Datei durch den PHP Parser schicken und so z.B. in Bilddateien versteckten PHP-Code auf dem Server ausführen.


nginx und php ist leider ein wenig kompliziert. Man kann da leicht einen Fehler machen.

Bei Apache bekommst du mehr oder weniger ein Standard-Setup frei Haus. Bei nginx machst du alles zu Fuß. Und wenn du dir da eine Config zusammenkopierst musst du trotzdem verstehen, was da passiert.

Lesenswert dazu auch nginx pitfalls

Nur-Ein-Blogger

(Themenstarter)

Anmeldungsdatum:
4. April 2011

Beiträge: 146

Okay, danke für die Info. Verstehe ich trotzdem noch nicht so recht. Dann kann ich ja bei nginx sowieso den Teil:

1
include /usr/local/nginx/conf/php.conf;

ja weglassen. Sollte ja dann trotzdem funktionieren. Testen werde ich es aber ich mag es nicht, etwas nicht zu verstehen, weil ich nicht wüsste was im allgemeinen da in seiner config bei ihm drinnen getsanden hätte.

LG

frostschutz

Avatar von frostschutz

Anmeldungsdatum:
18. November 2010

Beiträge: 7790

Die nginx Konfiguration lässt sich eben beliebig in mehrere Dateien aufsplitten. Eine php.conf kann von daher alles mögliche sein.

Bei Ubuntu gibts eine /etc/nginx/snippets/fastcgi-php.conf so in die Richtung wird es dann wohl gehen.

Es kommt ja auch drauf an, wie PHP umgesetzt ist. Da gibts verschiedene Möglichkeiten.

Auch wenn php-fpm so quasi der Standard ist.

Nur-Ein-Blogger

(Themenstarter)

Anmeldungsdatum:
4. April 2011

Beiträge: 146

Okay, ich teste nachher mal diese Config (der PATHNAME wird per sed eingepasst. Falls als die installation in domain.tld/blog ist, wird der path in "blog" ersetzt und nginx neu geladen)

  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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# wp-secure.conf
#
#
# This file includes common security considerations for wordpress using nginx.
#
# The goal is to block actions which are usually dangerous to wordpress.
# Additionally, we block direct access to PHP files and folders which should not 
# be accessed directly from a browser.
#
# Also have included exceptions for plugins that are known to require this access.


# Optional HTTP authentication for wp-login and wp-admin areas

#location ~* /(wp-login\.php) {
#    limit_req zone=xwplogin burst=1 nodelay;
#    auth_basic "Authorization Required";
#    auth_basic_user_file /usr/local/nginx/conf/htpasswd; 
#  #  # include /usr/local/nginx/conf/php.conf;
#}
#
#location ~* /wp-admin/.*\.php$ {
#	auth_basic "Authorization Required";
#    auth_basic_user_file /usr/local/nginx/conf/htpasswd;
#	# include /usr/local/nginx/conf/php.conf;
#}

# allow AJAX requests in themes and plugins
location ~ ^/WORDPRESSPATHNAME/wp-admin/admin-ajax.php$ { allow all; # include /usr/local/nginx/conf/php.conf; }

#Deny access to wp-content folders for suspicious files
location ~* ^/WORDPRESSPATHNAME/(wp-content)/(.*?)\.(zip|gz|tar|bzip2|7z)\$ { deny all; }
location ~ ^/WORDPRESSPATHNAME/wp-content/uploads/sucuri { deny all; }
location ~ ^/WORDPRESSPATHNAME/wp-content/updraft { deny all; }

# Block nginx-help log from public viewing
location ~* /WORDPRESSPATHNAME/wp-content/uploads/nginx-helper/ { deny all; }
location ~ ^/WORDPRESSPATHNAME/(wp-includes/js/tinymce/wp-tinymce.php) {
#  # include /usr/local/nginx/conf/php.conf;

}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
location ~* /WORDPRESSPATHNAME/(?:uploads|files)/.*\.php\$ { deny all; }

# Deny access to uploads that aren’t images, videos, music, etc.
location ~* ^/WORDPRESSPATHNAME/wp-content/uploads/.*.(html|htm|shtml|php|js|swf|css)$ {
    deny all;
}

# Whitelist Exception for https://wordpress.org/plugins/onesignal-free-web-push-notifications//
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/onesignal-free-web-push-notifications/ {
#  # include /usr/local/nginx/conf/php.conf;
}
# Whitelist Exception for https://wordpress.org/plugins/sparkpost/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/sparkpost/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/sendgrid-email-delivery-simplified/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/sendgrid-email-delivery-simplified/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/mailgun/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/mailgun/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/mailjet-for-wordpress/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/mailjet-for-wordpress/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/easy-wp-smtp/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/easy-wp-smtp/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/postman-smtp/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/postman-smtp/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/sendpress/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/sendpress/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wp-mail-bank/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wp-mail-bank/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/theme-check/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/theme-check/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/woocommerce/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/woocommerce/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/woocommerce-csvimport/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/woocommerce-csvimport/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/advanced-custom-fields/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/advanced-custom-fields/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/contact-form-7/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/contact-form-7/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/duplicator/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/duplicator/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/jetpack/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/jetpack/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/nextgen-gallery/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/nextgen-gallery/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/tinymce-advanced/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/tinymce-advanced/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/updraftplus/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/updraftplus/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wordpress-importer/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wordpress-importer/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wordpress-seo/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wordpress-seo/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wpclef/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wpclef/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/mailchimp-for-wp/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/mailchimp-for-wp/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wp-optimize/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wp-optimize/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/si-contact-form/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/si-contact-form/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/akismet/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/akismet/ {
  location ~ ^/wp-content/plugins/akismet/(.+/)?(form|akismet)\.(css|js)\$ { allow all; }
  location ~ ^/wp-content/plugins/akismet/(.+/)?(.+)\.(png|gif)\$ { allow all; }
  location ~* /wp-content/plugins/akismet/akismet/.*\.php\$ {
  #  # include /usr/local/nginx/conf/php.conf;
    allow 127.0.0.1;
    deny all;
  }
}
# Whitelist Exception for https://wordpress.org/plugins/bbpress/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/bbpress/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/buddypress/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/buddypress/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/all-in-one-seo-pack/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/all-in-one-seo-pack/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/google-analytics-for-wordpress/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/google-analytics-for-wordpress/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/regenerate-thumbnails/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/regenerate-thumbnails/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wp-pagenavi/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wp-pagenavi/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wordfence/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wordfence/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/really-simple-captcha/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/really-simple-captcha/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/wp-pagenavi/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wp-pagenavi/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/ml-slider/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/ml-slider/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/black-studio-tinymce-widget/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/black-studio-tinymce-widget/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/disable-comments/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/disable-comments/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/better-wp-security/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/better-wp-security/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for http://wlmsocial.com/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/wlm-social/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for mediagrid timthumb
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/media-grid/classes/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Whitelist Exception for https://wordpress.org/plugins/sparkpost/
location ~ ^/WORDPRESSPATHNAME/wp-content/plugins/comet-cache/ {
#  # include /usr/local/nginx/conf/php.conf;

}
# Block PHP files in content directory.
location ~* /WORDPRESSPATHNAME/wp-content/.*\.php\$ {
  deny all;
}
# Block PHP files in includes directory.
location ~* /WORDPRESSPATHNAME/wp-includes/.*\.php\$ {
  deny all;
}
# Block PHP files in uploads, content, and includes directory.
location ~* /WORDPRESSPATHNAME/(?:uploads|files|wp-content|wp-includes)/.*\.php\$ {
  deny all;
}
# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* /WORDPRESSPATHNAME/ \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)\$|^(\..*|Entries.*|Repository|Root|Tag|Template)\$|\.php_
{
return 444;
}
#nocgi
location ~* /WORDPRESSPATHNAME/ \.(pl|cgi|py|sh|lua)\$ {
return 444;
}
#disallow
location ~* /WORDPRESSPATHNAME/ (w00tw00t) {
return 444;
}
location ~* /WORDPRESSPATHNAME/(\.|wp-config\.php|wp-config\.txt|changelog\.txt|readme\.txt|readme\.html|license\.txt) { deny all; }

# Stop image hotlinking
location ~ /WORDPRESSPATHNAME/ .(gif|png|jpe?g)$ {
     valid_referers none blocked REPLACEDOMAIN *.REPLACEDOMAIN;
     if ($invalid_referer) {
        return   403;
    }
}

frostschutz

Avatar von frostschutz

Anmeldungsdatum:
18. November 2010

Beiträge: 7790

Naja, mit leeren Locations wird dir das nicht helfen - es sei denn du willst, daß diese Sachen nicht funktionieren, aber bei der Whitelist soll das ja gehen.

Ich würde diese Config gar nicht verwenden.

Aber ich betreibe auch kein Wordpress... gibt es da für 0815 Apache-PHP Installationen wirklich so eine Blacklist-Whitelist per .htaccess um das sicher zu machen? Ich kann mir das irgendwie nicht so richtig vorstellen.

Einen Link hab ich hier noch gefunden: https://www.nginx.com/blog/9-tips-for-improving-wordpress-performance-with-nginx/

Da hat es auch einen Abschnitt zum Thema Wordpress absichern.

misterunknown Team-Icon

Ehemalige
Avatar von misterunknown

Anmeldungsdatum:
28. Oktober 2009

Beiträge: 4403

Wohnort: Sachsen

Zum Thema Wordpress und Sicherheit hab ich auch mal ein paar Gedanken zusammengetragen: https://misterunknown.de/blog/2017/03/wordpress-wichtige-sicherheitsmassnahmen.html.

Nginx als Webserver für Wordpress ist meiner Meinung nach nicht zu empfehlen! Nimm lieber der Apache.

Antworten |