Nginx configuration file locations

 

Overview

This article explains where configuration files should be placed on Nginx servers at DreamHost. View the following articles for examples of custom configuration files you could create:

Will my .htaccess file function?

Nginx does not support directory-level configurations (such as .htaccess) outside of the primary server configuration file. However, it's still possible to set up local configuration files under your username.

Local website configuration files

This section explains how to create a directory for website configuration files.

Where should configuration files be placed?

Nginx uses a directory named /nginx under your website username. In this directory, you'll add another directory for your website. For example:

/home/username/nginx/example.com

This is the only directory you should place any configuration files you want your website to use.

The /nginx/example.com directory does not exist by default. You must create it manually.

Creating the configuration directory

  1. Log into your server via SSH.
  2. Navigate to your user's home directory.
  3. Run the following command:
    [server]$ mkdir -p nginx/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

How should files be named?

You can name your files anything you like, but they must all use the .conf extension. Nginx will look for files with this extension to insert into the server block of the nginx.conf file.

The nginx.conf file (Dedicated servers only)

The server's config file can only be seen or edited if you're using an admin user on a Dedicated Server.

  1. Log into your Dedicated Server via SSH.
  2. Navigate to the /etc/nginx directory:
    [server]$ cd /etc/nginx
  3. Use sudo to view the directory contents:
    [server]$ sudo ls -la
  4. Enter your password when prompted. You'll see the nginx.conf file listed.
  5. Edit the file using sudo:
    [server]$ sudo nano nginx.conf
    
  6. Save and close the file and return to your shell.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?