Skip to content

Commit 78298aa

Browse files
author
António P. P. Almeida
committed
* Initial commit of WP Nginx config wp-super-cache compatible.
0 parents  commit 78298aa

11 files changed

+916
-0
lines changed

README.md

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Nginx configuration for WordPress
2+
3+
## Introduction
4+
5+
This is a nginx configuration for running [WordPress](http://wordpress.org "WordPress").
6+
7+
It differs from the _usual_ configuration, like the
8+
[one](http://wiki.nginx.org/Wordpress "Nginx Wiki WordPress
9+
config") available on the [Nginx Wiki](http://wiki.nginx.org "Nginx
10+
Wiki").
11+
12+
It makes use of **nested locations** with named capture groups
13+
instead of
14+
[fastcgi_split\_path\_info](http://wiki.nginx.org/HttpFcgiModule#fastcgi_split_path_info
15+
"FastCGI split path info").
16+
17+
This example configuration assumes that the site is called
18+
`example.com`. Change accordingly to reflect your server setup.
19+
20+
## Features
21+
22+
1. Filtering of invalid HTTP `Host` headers.
23+
24+
2. Access to install files, like `install.php,` is protected using
25+
[HTTP Basic Auth](http://wiki.nginx.org/NginxHttpAuthBasicModule
26+
"Basic Auth Nginx Module").
27+
28+
3. Protection of all the _internal_ directories, like version
29+
control repositories and the `readme` file(s)
30+
that come with WP or an external plugin.
31+
32+
4. Faster and more secure handling of PHP FastCGI by Nginx using
33+
named groups in regular expressions instead of using
34+
[fastcgi_split\_path\_info](http://wiki.nginx.org/HttpFcgiModule#fastcgi_split_path_info
35+
"FastCGI split path info"). Requires Nginx version ≥ 0.8.25.
36+
37+
5. Compatible with the WordPress plugin
38+
[wp-super-cache](http://wordpress.org/extend/plugins/wp-super-cache "WordPress
39+
SuperCache") for serving static pages to anonymous users.
40+
41+
42+
## Basic Auth for access to restricted files like install.php
43+
44+
`install.php` and the WordPress `readme.html` are protected using
45+
Basic Auth. The readme file discloses the version number of
46+
WordPress.
47+
48+
Not only `install.php`, but any PHP file that has **install.php**
49+
as the ending is protected. This way if, for example, there's a
50+
permission problem with `wp-config.php` and WP can't read the file
51+
it will invoke `install.php` since it assumes that if no specific
52+
configuration information is available then the site must not yet
53+
be installed. Now imagine that this happens on your site and that
54+
someone stumbles on the `install.php`? If not protected by the
55+
Basic Auth, information disclosure would be the least potential
56+
problem.
57+
58+
You have to create the `.htpasswd-users` file with the user(s) and
59+
password(s). For that, if you're on Debian or any of its
60+
derivatives like Ubuntu you need the
61+
[apache2-utils](http://packages.debian.org/search?suite%3Dall&section%3Dall&arch%3Dany&searchon%3Dnames&keywords%3Dapache2-utils)
62+
package installed. Then create your password file by issuing:
63+
64+
htpasswd -d -b -c .htpasswd-users <user> <password>
65+
66+
You should delete this command from your shell history
67+
afterwards with `history -d <command number>` or alternatively
68+
omit the `-b` switch, then you'll be prompted for the password.
69+
70+
This creates the file (there's a `-c` switch). For adding
71+
additional users omit the `-c`.
72+
73+
Of course you can rename the password file to whatever you want,
74+
then accordingly change its name in the virtual host config
75+
file, `example.com`.
76+
77+
## Installation
78+
79+
1. Move the old `/etc/nginx` directory to `/etc/nginx.old`.
80+
81+
2. Clone the git repository from github:
82+
83+
`git clone https://github.com/perusio/chive-wordpress.git`
84+
85+
3. Edit the `sites-available/example.com` configuration file to
86+
suit your requirements. Namely replacing `example.com` with
87+
**your** domain.
88+
89+
4. Setup the PHP handling method. It can be:
90+
91+
+ Upstream HTTP server like Apache with mod_php
92+
93+
+ FastCGI process using php-cgi. In this case an
94+
[init script](https://github.com/perusio/php-fastcgi-debian-script
95+
"Init script for php-cgi") is
96+
required. This is how the server is configured out of the
97+
box. It uses UNIX sockets. You can use TCP sockets if you prefer.
98+
99+
+ [PHP FPM](http://www.php-fpm.org "PHP FPM"), this requires you
100+
to configure your fpm setup, in Debian/Ubuntu this is done in
101+
the `/etc/php5/fpm` directory.
102+
103+
Check that the socket is properly created and is listening. This
104+
can be done with `netstat`, like this for UNIX sockets:
105+
106+
`netstat --unix -l`
107+
108+
`netstat -t -l`
109+
110+
It should display the PHP CGI socket.
111+
112+
5. Create the `/etc/nginx/sites-enabled` directory and enable the
113+
virtual host using one of the methods described below.
114+
115+
6. Reload Nginx:
116+
117+
`/etc/init.d/nginx reload`
118+
119+
7. Check that WordPress is working by visiting the configured site
120+
in your browser.
121+
122+
8. Remove the `/etc/nginx.old` directory.
123+
124+
9. Done.
125+
126+
## Enabling and Disabling Virtual Hosts
127+
128+
I've created a shell script
129+
[nginx_ensite](http://github.com/perusio/nginx_ensite) that lives
130+
here on github for quick enabling and disabling of virtual hosts.
131+
132+
If you're not using that script then you have to **manually**
133+
create the symlinks from `sites-enabled` to `sites-available`. Only
134+
the virtual hosts configured in `sites-enabled` will be available
135+
for Nginx to serve.
136+
137+
138+
## Getting the latest Nginx packaged for Debian or Ubuntu
139+
140+
I maintain a [debian repository](http://debian.perusio.net/unstable
141+
"my debian repo") with the
142+
[latest](http://nginx.org/en/download.html "Nginx source download")
143+
version of Nginx. This is packaged for Debian **unstable** or
144+
**testing**. The instructions for using the repository are
145+
presented on this [page](http://debian.perusio.net/debian.html
146+
"Repository instructions").
147+
148+
It may work or not on Ubuntu. Since Ubuntu seems to appreciate more
149+
finding semi-witty names for their releases instead of making clear
150+
what's the status of the software included, meaning. Is it
151+
**stable**? Is it **testing**? Is it **unstable**? The package may
152+
work with your currently installed environment or not. I don't have
153+
the faintest idea which release to advise. So you're on your
154+
own. Generally the APT machinery will sort out for you any
155+
dependencies issues that might exist.
156+
157+
## My other Nginx configurations on github
158+
159+
+ [drupal](https://github.com/perusio/drupal-with-nginx "Drupal
160+
Nginx configuration")
161+
162+
+ [piwik](https://github.com/perusio/piwik-nginx "Piwik Nginx
163+
configuration")
164+
165+
+ [chive](https://github.com/perusio/piwik-nginx "Chive Nginx
166+
configuration")
167+

fastcgi.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#-*- mode: nginx; mode: flyspell-prog; mode: autopair; ispell-local-dictionary: "american" -*-
2+
### fastcgi configuration.
3+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
4+
include fastcgi_params;
5+
fastcgi_buffers 256 4k;
6+
fastcgi_intercept_errors on;
7+
## allow 4 hrs - pass timeout responsibility to upstrea
8+
fastcgi_read_timeout 14400;
9+
fastcgi_index index.php;

fastcgi_params

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- mode: nginx; mode: flyspell-prog; mode: autopair; ispell-local-dictionary: "american" -*-
2+
### fastcgi parameters.
3+
fastcgi_param QUERY_STRING $query_string;
4+
fastcgi_param REQUEST_METHOD $request_method;
5+
fastcgi_param CONTENT_TYPE $content_type;
6+
fastcgi_param CONTENT_LENGTH $content_length;
7+
8+
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
9+
fastcgi_param REQUEST_URI $request_uri;
10+
fastcgi_param DOCUMENT_URI $document_uri;
11+
fastcgi_param DOCUMENT_ROOT $document_root;
12+
fastcgi_param SERVER_PROTOCOL $server_protocol;
13+
14+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
15+
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
16+
17+
fastcgi_param REMOTE_ADDR $remote_addr;
18+
fastcgi_param REMOTE_PORT $remote_port;
19+
fastcgi_param SERVER_ADDR $server_addr;
20+
fastcgi_param SERVER_PORT $server_port;
21+
fastcgi_param SERVER_NAME $server_name;
22+
23+
# PHP only, required if PHP was built with --enable-force-cgi-redirect
24+
fastcgi_param REDIRECT_STATUS 200;

koi-utf

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
2+
# This map is not a full koi8-r <> utf8 map: it does not contain
3+
# box-drawing and some other characters. Besides this map contains
4+
# several koi8-u and Byelorussian letters which are not in koi8-r.
5+
# If you need a full and standard map, use contrib/unicode2nginx/koi-utf
6+
# map instead.
7+
8+
charset_map koi8-r utf-8 {
9+
10+
80 E282AC ; # euro
11+
12+
95 E280A2 ; # bullet
13+
14+
9A C2A0 ; # &nbsp;
15+
16+
9E C2B7 ; # &middot;
17+
18+
A3 D191 ; # small yo
19+
A4 D194 ; # small Ukrainian ye
20+
21+
A6 D196 ; # small Ukrainian i
22+
A7 D197 ; # small Ukrainian yi
23+
24+
AD D291 ; # small Ukrainian soft g
25+
AE D19E ; # small Byelorussian short u
26+
27+
B0 C2B0 ; # &deg;
28+
29+
B3 D081 ; # capital YO
30+
B4 D084 ; # capital Ukrainian YE
31+
32+
B6 D086 ; # capital Ukrainian I
33+
B7 D087 ; # capital Ukrainian YI
34+
35+
B9 E28496 ; # numero sign
36+
37+
BD D290 ; # capital Ukrainian soft G
38+
BE D18E ; # capital Byelorussian short U
39+
40+
BF C2A9 ; # (C)
41+
42+
C0 D18E ; # small yu
43+
C1 D0B0 ; # small a
44+
C2 D0B1 ; # small b
45+
C3 D186 ; # small ts
46+
C4 D0B4 ; # small d
47+
C5 D0B5 ; # small ye
48+
C6 D184 ; # small f
49+
C7 D0B3 ; # small g
50+
C8 D185 ; # small kh
51+
C9 D0B8 ; # small i
52+
CA D0B9 ; # small j
53+
CB D0BA ; # small k
54+
CC D0BB ; # small l
55+
CD D0BC ; # small m
56+
CE D0BD ; # small n
57+
CF D0BE ; # small o
58+
59+
D0 D0BF ; # small p
60+
D1 D18F ; # small ya
61+
D2 D180 ; # small r
62+
D3 D181 ; # small s
63+
D4 D182 ; # small t
64+
D5 D183 ; # small u
65+
D6 D0B6 ; # small zh
66+
D7 D0B2 ; # small v
67+
D8 D18C ; # small soft sign
68+
D9 D18B ; # small y
69+
DA D0B7 ; # small z
70+
DB D188 ; # small sh
71+
DC D18D ; # small e
72+
DD D189 ; # small shch
73+
DE D187 ; # small ch
74+
DF D18A ; # small hard sign
75+
76+
E0 D0AE ; # capital YU
77+
E1 D090 ; # capital A
78+
E2 D091 ; # capital B
79+
E3 D0A6 ; # capital TS
80+
E4 D094 ; # capital D
81+
E5 D095 ; # capital YE
82+
E6 D0A4 ; # capital F
83+
E7 D093 ; # capital G
84+
E8 D0A5 ; # capital KH
85+
E9 D098 ; # capital I
86+
EA D099 ; # capital J
87+
EB D09A ; # capital K
88+
EC D09B ; # capital L
89+
ED D09C ; # capital M
90+
EE D09D ; # capital N
91+
EF D09E ; # capital O
92+
93+
F0 D09F ; # capital P
94+
F1 D0AF ; # capital YA
95+
F2 D0A0 ; # capital R
96+
F3 D0A1 ; # capital S
97+
F4 D0A2 ; # capital T
98+
F5 D0A3 ; # capital U
99+
F6 D096 ; # capital ZH
100+
F7 D092 ; # capital V
101+
F8 D0AC ; # capital soft sign
102+
F9 D0AB ; # capital Y
103+
FA D097 ; # capital Z
104+
FB D0A8 ; # capital SH
105+
FC D0AD ; # capital E
106+
FD D0A9 ; # capital SHCH
107+
FE D0A7 ; # capital CH
108+
FF D0AA ; # capital hard sign
109+
}

0 commit comments

Comments
 (0)