NGINX – example nginx.conf configuration

There are many options and directives that can be used inside nginx.conf. Below is example “starter” configuration that we are using on our newly spawn EC2 instances. We decided to share it as it seems to be working ok on quite few of our servers.

This is example configuration for NginX allowing you to use websites-available  and websites-enabled  directories to manage your websites. It has been created with article NginX – Custom build and installation for AWS EC2 in mind. If you wish you can however use it with custom NginX installation modifying some of those bits adjusting it to your needs.

And here is the content of  nginx.conf file

Note: If you have problems with pasting configuration using vim editor use :set paste” on Vim’s command interface to disable auto-indenting. Now you can paste the block(s) of code. When you done disable the paste mode through the command “:set nopaste

Freelance developer, IT enthusiast, blogger with entrepreneurial spirit and passion for making games

Tagged with:
, , , , ,
Posted in
AWS, Technical
4 comments on “NGINX – example nginx.conf configuration
  1. Hello thank you for your tutorials !
    Using this configuration file i get:
    nginx: [emerg] unknown log format “main” in /etc/nginx/nginx.conf:15

  2. Saurabh Ganeriwal says:

    I am having trouble in getting nginx to run on AWS EC2. I did my own compile of nginx because I wanted to enable SSL and SPDY. I also install it in a specific directory (/usr/local/abcd). After installation, I am successfully able to start nginx (/usr/local/abcd/nginx/sbin/nginx) but the default welcome page is not showing. Any suggestions. My conf file is very simple and so I am not sure what can be the issue. I am also sure that the path to the conf file is right and I am passing it using the -c flag, as if I make a simply typo in this file nginx start fails with an error.

    Few things:
    1. Can you see any errors in the following configuration
    2. Any other static paths that I need to change
    3. Any other way to verify besides relying on the error page.
    4. Interestingly there is no access that is getting shown in access.log

    user www-data www-data;
    worker_processes 1;

    error_log logs/error.log;
    pid logs/;

    events {
    worker_connections 1024;

    http {
    include mime.types;
    default_type application/octet-stream;
    access_log logs/access.log;
    server {
    listen 80 default_server;
    index index.html;
    root /usr/local/abcd/nginx/html;

    • Can’t see the error with naked eye. I would recommend to use minimum working configuration and then extend / modify it step by step. You will quickly be able to discover the error.

      My first bet would be incorrect path but I assume you have verified that already, haven’t you?

      What error are you getting on the screen?

1 Pings/Trackbacks for "NGINX – example nginx.conf configuration"
  1. [...] NGINX – example nginx.conf configuration - you can use this example to gain better controll and improve NginX maintainability [...]

Leave a Reply