Overview
DreamHost Nginx servers support custom per-website configuration through .conf files you create under your username at /home/username/nginx/example.com. Nginx inserts those files into the server block of the main nginx.conf file, giving you fine-grained control over server behavior for each site.
For examples of custom configuration files you can create, see:
- How to make statistics and permalinks work with WordPress and Nginx
- Password protecting directories with Nginx
- Creating redirects with Nginx
- Blocking IPs with Nginx
What is the Nginx configuration directory?
The Nginx configuration directory is a location separate from your website directory, created under your username, where you place the .conf files for your site. This section covers where it goes, how to create it, and how it relates to your website directory.
DreamPress plans do not support changes to the local Nginx configuration directory. To customize the nginx.conf file on DreamPress, contact support.
Where do configuration files go?
Place your .conf files in a directory named /nginx under your website username's home directory, inside a subdirectory named for your website. This is the only directory where Nginx looks for per-site configuration files:
/home/username/nginx/example.com
The /nginx/example.com directories do not exist by default and must be created manually.
How do I create the configuration directory?
- Log in to your server via SSH.
- Navigate to your user's home directory.
-
Run the following command:
[server]$ mkdir -p nginx/example.com
What are the two website directories?
After creating the configuration directory, your website uses two separate directories:
- Website directory — where your website files are located:
- Nginx configuration directory — where your .conf files are located:
/home/username/example.com
/home/username/nginx/example.com
How should configuration files be named?
You can give your configuration files any name, but they must use the .conf extension. Nginx identifies files by this extension when inserting them into the server block of nginx.conf.
Does Nginx support .htaccess files?
No. Nginx does not support directory-level configuration files such as .htaccess. Use the local /nginx/example.com configuration directory described above instead.
Do I need to reload Nginx after editing configuration files?
Yes. Changes to your .conf files do not take effect until Nginx is reloaded or restarted. After saving any edits to a configuration file, reload or restart the Nginx server to apply them.
See How to reload and restart Nginx for instructions.
How do I edit the nginx.conf file on a Dedicated Server?
On a Dedicated Server, you can view and edit the main nginx.conf file directly when logged in as an admin user. This requires an admin user on a Dedicated Server.
- Log in to your Dedicated Server via SSH.
-
Navigate to the /etc/nginx directory:
[server]$ cd /etc/nginx
-
Use sudo to view the directory contents:
[server]$ sudo ls -la
- Enter your password when prompted. The nginx.conf file appears in the listing.
-
Edit the file using sudo:
[server]$ sudo nano nginx.conf
- Save and close the file and return to your shell.