Overview
If you have changed your web server to Nginx, you will notice certain configuration files (such as .htaccess) no longer function. This is because Nginx does not support directory-level configurations outside of the primary server configuration file. However, it's still possible to set up local configuration files under your username for customizations like a redirect.
This article lists the different configuration file locations for Nginx at DreamHost.
Local configuration files
Nginx enables an /nginx directory under your website username. It is located in the following directory:
In the following examples, username would be your Shell user and example.com your website.
/home/username/nginx/example.com
This directory is the only place you should load any .conf file you want your website to use. Additionally, any file ending in .conf is inserted into the server block of the nginx.conf file.
Creating the configuration directory
The /nginx/example.com directories do not exist by default. You must create them manually by running the following command under your username:
- Log into your server via SSH.
- Navigate to your user's home directory.
- Run the following command:
[server]$ mkdir -p nginx/example.com
You can now add your custom configuration files ending in .conf to this directory for the website example.com.
The two Nginx directories
To clarify, you'll now have two directories your domain uses:
Your website directory
This is your website directory where all files are located.
-
/home/username/example.com
Your nginx configuration directory
This is where all Nginx config files are located.
-
/home/username/nginx/example.com
The nginx.conf file (Dedicated servers only)
This example contains examples using sudo/admin users. If you require sudo/admin access, you must upgrade to a Dedicated Server.
The main config file can only be seen or edited if you're using an admin user on a Dedicated Server.
- Log into your Dedicated Server 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.
- You'll see the nginx.conf file listed.
- Edit the file using sudo:
[server]$ sudo nano nginx.conf
- Save and close the file and return to your shell.
Examples of .conf files
View the following articles for examples on what a custom .conf file would look like for your site: