Skip to content
This repository was archived by the owner on Sep 23, 2022. It is now read-only.

Commit 07a24c8

Browse files
committed
Add sample configuration for apache / nginx web servers.
1 parent 37b3ce4 commit 07a24c8

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

dist/apache/sample.htaccess

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
4+
RewriteBase "/"
5+
6+
#Fix issue #1 invalid wp-admin redirect
7+
RewriteRule ^wp\-admin$ /wp-admin/ [L,R=301]
8+
9+
#If the URL start with public stop redirect
10+
RewriteRule wp\-cms\/index\.php$ - [L]
11+
12+
#If you request an URL it does not start with wp-cms
13+
#Else the HTACCESS have done the redirect, you can go to the index.php to execute code
14+
RewriteCond %{REQUEST_URI} ^/wp-cms
15+
RewriteCond %{REQUEST_FILENAME} !-f
16+
RewriteCond %{REQUEST_FILENAME} !-d
17+
RewriteRule ^(.*)$ /wp-cms/index.php [L]
18+
19+
#wp-cms is not here so we add it :)
20+
RewriteCond %{REQUEST_FILENAME} !-f
21+
RewriteCond %{REQUEST_FILENAME} !-d
22+
RewriteRule ^(.*)$ /wp-cms/$1 [L]
23+
</IfModule>
24+
25+
########################### MOD_DEFLATE COMPRESSION ############################
26+
<IfModule mod_deflate.c>
27+
SetOutputFilter DEFLATE
28+
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
29+
</IfModule>
30+
31+
#For incompatible browsers
32+
BrowserMatch ^Mozilla/4 gzip-only-text/html
33+
BrowserMatch ^Mozilla/4\.0[678] no-gzip
34+
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
35+
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
36+
37+
#Do not put in cache if files are already in
38+
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|swf)$ no-gzip
39+
40+
################################ EXPIRE HEADERS ################################
41+
<IfModule mod_expires.c>
42+
ExpiresActive On
43+
ExpiresDefault "access plus 7200 seconds"
44+
ExpiresByType image/jpg "access plus 2592000 seconds"
45+
ExpiresByType image/jpeg "access plus 2592000 seconds"
46+
ExpiresByType image/png "access plus 2592000 seconds"
47+
ExpiresByType image/gif "access plus 2592000 seconds"
48+
49+
AddType image/x-icon .ico
50+
ExpiresByType image/ico "access plus 2592000 seconds"
51+
ExpiresByType image/icon "access plus 2592000 seconds"
52+
ExpiresByType image/x-icon "access plus 2592000 seconds"
53+
ExpiresByType text/css "access plus 2592000 seconds"
54+
ExpiresByType text/javascript "access plus 2592000 seconds"
55+
ExpiresByType text/html "access plus 7200 seconds"
56+
ExpiresByType application/xhtml+xml "access plus 7200 seconds"
57+
ExpiresByType application/javascript A259200
58+
ExpiresByType application/x-javascript "access plus 2592000 seconds"
59+
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
60+
</IfModule>
61+
62+
############################ CACHE CONTROL HEADERS #############################
63+
<IfModule mod_headers.c>
64+
#les proxies doivent donner le bon contenu
65+
Header append Vary User-Agent env=!dont-vary
66+
67+
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|gz|ttf)$">
68+
Header set Cache-Control "max-age=2592000, public"
69+
</FilesMatch>
70+
<FilesMatch "\\.(css)$">
71+
Header set Cache-Control "max-age=2592000, public"
72+
</FilesMatch>
73+
<FilesMatch "\\.(js)$">
74+
Header set Cache-Control "max-age=2592000, private"
75+
</FilesMatch>
76+
<FilesMatch "\\.(html|htm)$">
77+
Header set Cache-Control "max-age=7200, public"
78+
</FilesMatch>
79+
80+
# Disable caching for scripts and other dynamic files
81+
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
82+
Header unset Cache-Control
83+
</FilesMatch>
84+
85+
# KILL THEM ETAGS
86+
Header unset ETag
87+
FileETag none
88+
</IfModule>
89+
90+
############################ PROTECT HTACCESS FILE #############################
91+
<Files .htaccess>
92+
Order allow,deny
93+
Deny from all
94+
</Files>
95+
<Files wp-config.php>
96+
Order allow,deny
97+
Deny from all
98+
</Files>
99+
100+
############################ PROTECT FOLDER LISTING ############################
101+
Options -Indexes

dist/nginx/sample.conf

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
upstream phpfpm-sock {
2+
server {sock};
3+
}
4+
5+
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone={host}:100m inactive=60m;
6+
fastcgi_cache_key "$scheme$request_method$host$request_uri";
7+
8+
server {
9+
listen 80;
10+
11+
server_name {host};
12+
root /home/{host}/public;
13+
14+
index index.php;
15+
16+
access_log /var/log/nginx/{host}-access.log;
17+
error_log /var/log/nginx/{host}-error.log;
18+
19+
set $root "";
20+
if ($request_uri ~* "^(/wp-admin/.+)|(/wp-[^/]+\.php)" ){
21+
set $root "/wp-cms";
22+
}
23+
24+
# Global restrictions configuration file.
25+
# Designed to be included in any server {} block.
26+
location = /favicon.ico {
27+
log_not_found off;
28+
access_log off;
29+
}
30+
31+
location = /robots.txt {
32+
allow all;
33+
log_not_found off;
34+
access_log off;
35+
}
36+
37+
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
38+
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
39+
location ~ /\.(?!well-known).+ {
40+
deny all;
41+
}
42+
43+
# Deny access to any files with a .php extension in the uploads directory
44+
# Works in sub-directory installs and also in multisite network
45+
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
46+
location ~* /(?:uploads|files)/.*\.php$ {
47+
deny all;
48+
}
49+
50+
# WordPress single site rules.
51+
# Designed to be included in any server {} block.
52+
53+
# This order might seem weird - this is attempted to match last if rules below fail.
54+
# http://wiki.nginx.org/HttpCoreModule
55+
location / {
56+
try_files $uri $uri/ /wp-cms/$uri /wp-cms/$uri/ /wp-cms/index.php?$args;
57+
}
58+
59+
# Add trailing slash to */wp-admin requests.
60+
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
61+
62+
# Directives to send expires headers and turn off 404 error logging.
63+
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
64+
access_log off;
65+
log_not_found off;
66+
expires max;
67+
}
68+
69+
# Pass all .php files onto a php-fpm/php-fcgi server.
70+
location ~ [^/]\.php(/|$) {
71+
fastcgi_split_path_info ^(/.+?\.php)(/.*)$;
72+
if (!-f $document_root$root$fastcgi_script_name) {
73+
return 404;
74+
}
75+
# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
76+
77+
include /etc/nginx/fastcgi_params;
78+
fastcgi_index index.php;
79+
fastcgi_param SCRIPT_FILENAME $document_root$root$fastcgi_script_name;
80+
fastcgi_pass phpfpm-sock;
81+
fastcgi_cache {host};
82+
fastcgi_cache_valid 200 60m;
83+
}
84+
}

0 commit comments

Comments
 (0)