Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuring nginx to serve static files from a custom directory

Tags:

nginx

So I want to serve static files from a specific folder on a specific port with Nginx.

$ nginx -c `pwd`/nginx.conf

my local nginx.conf goes like:

http {
    server {
        root .;
        listen 8080;
    }
}

but i'm getting this error:

nginx: [emerg] no "events" section in configuration

I can see the events section in /etc/nginx/nginx.conf but I don't want to have to duplicate all the configuration. There has to be a way to use the default settings and just different port number for a specific folder.

What am I missing to get this to work?

like image 941
Renaud Avatar asked Aug 22 '14 13:08

Renaud


People also ask

How do I set nginx to serve static files?

To serve static files with nginx, you should configure the path of your application's root directory and reference the HTML entry point as the index file.

Is nginx used for serving static content?

Configure NGINX and NGINX Plus to serve static content, with type-specific root directories, checks for file existence, and performance optimizations.


1 Answers

You need to specify minimal events block:

events {
    worker_connections        1024;
}

Root needs to be declared with absolute path on the filesystem.

like image 142
Anatoly Avatar answered Sep 30 '22 08:09

Anatoly