wordpress-nginx/README.md
2015-11-23 11:34:56 +00:00

82 lines
3.0 KiB
Markdown

# WordPress Nginx
Nginx configuration geared towards hosting WordPress sites. Contains best practices from various sources, including the [WordPress Codex](https://codex.wordpress.org/Nginx) and [H5BP](https://github.com/h5bp/server-configs-nginx). The following example sites are included:
* singlesite.com - WordPress single site install (no SSL or page caching)
* ssl.com - WordPress on HTTPS
* fastcgi-cache.com - WordPress with [FastCGI caching](https://deliciousbrains.com/hosting-wordpress-yourself-server-monitoring-caching/#page-cache)
* multisite-subdomain.com - WordPress Multisite install using subdomains
* multisite-subdirectory.com - WordPress Multisite install using subdirectories
## Usage
You can use these sample configurations as reference or directly by replacing your existing nginx directory. Follow the steps below to replace your existing nginx configuration.
Backup any existing config:
`sudo mv /etc/nginx /etc/nginx.backup`
Clone the repo:
`sudo git clone https://github.com/A5hleyRich/wordpress-nginx.git /etc/nginx`
Symlink the default file from _sites-available_ to _sites-enabled_, which will setup a catch-all server block. This will ensure unrecognised domains return a 444 response.
`sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default`
Copy one of the example configurations from _sites-available_ to _sites-available/yourdomain.com_:
sudo cp /etc/nginx/sites-available/singlesite.com /etc/nginx/sites-available/yourdomain.com`
Edit the site accordingly, paying close attention to the server name and paths.
To enable the site, symlink the configuration into the _sites-enabled_ directory:
`sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/yourdomain.com`
Test the configuration:
`sudo nginx -t`
If the configuration passes, restart Nginx:
`sudo /etc/init.d/nginx reload`
## Directory Structure
This repository has the following structure, which is based on the conventions used by a default Nginx install on Debian:
```
.
├── conf.d
├── global
└── server
├── sites-available
├── sites-enabled
```
__conf.d__ - configurations for additional modules.
__global__ - configurations within the `http` block.
__global/server__ - configurations within the `server` block. The `defaults.con` file should be included on the majority of sites, which contains sensible defaults for caching, file exclusions and security. Additional `.conf` files can be included as needed on a per-site basis.
__sites-available__ - configurations for individual sites (virtual hosts).
__sites-enabled__ - symlinks to configurations within the `sites-available` directory. Only sites which have been symlinked are loaded.
### Recommended Site Structure
The following site structure is used throughout this repository:
```
.
├── yourdomain1.com
└── cache
└── logs
└── public
├── yourdomain2.com
└── cache
└── logs
└── public
```