Coder Social home page Coder Social logo

docker-nginx's Introduction

docker-nginx

A high-performance Nginx base image for Docker to serve static websites. It will serve anything in the /var/www directory.

To build a Docker image for your site, you'll need to create a Dockerfile. For example, if your site is in a directory called src/, you could create this Dockerfile:

FROM kyma/docker-nginx
COPY src/ /var/www
CMD 'nginx'

Then build and run it:

$ docker build -t mysite .
...
Successfully built 5ae2fb5cf4f8
$ docker run -p 80:80 -d mysite
da809981545f
$ curl localhost
...

Docker Hub

The trusted build information can be found on the Docker Hub at https://registry.hub.docker.com/u/kyma/docker-nginx/.

SSL

To use SSL, put your certs in /etc/nginx/ssl and enable the default-ssl site:

ADD server.crt /etc/nginx/ssl/
ADD server.key /etc/nginx/ssl/
RUN ln -s /etc/nginx/sites-available/default-ssl /etc/nginx/sites-enabled/default-ssl

When you run it, you'll want to make port 443 available, e.g.:

$ docker run -p 80:80 -p 443:443 -d mysite

nginx.conf

The nginx.conf and mime.types are pulled with slight modifications from the h5bp Nginx HTTP server boilerplate configs project at https://github.com/h5bp/server-configs-nginx

Customized configs

To modify the NGINX config, you would just create a custom Dockerfile like the following where you copy in your modified config files.

# Guide here:
# https://github.com/KyleAMathews/docker-nginx

# Build docker file
# docker build -t CONTAINERNAME .

# Build from this repo's image
FROM kyma/docker-nginx

# Example if you wanna swap the default server file.
COPY path/to/your/default /etc/nginx/sites-enabled/default

# Add src.
COPY src/ /var/www

CMD 'nginx'

docker-nginx's People

Contributors

bfirsh avatar kyleamathews avatar pierreozoux avatar sp90 avatar tedyoung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-nginx's Issues

Missing LICENSE file

This project is missing a LICENSE file. From: https://opensource.google.com/docs/using/license/

The OSI collects a set of licenses which grant the relevant rights for open source projects. They also maintain a widely-accepted document which outlines what makes a license open source.

Examples of unambiguous permissions are:

Section 2 of the Apache License, which grants an “irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute”.

The MIT license grants “the rights to use, copy, modify, merge, publish, distribute, sublicense”.

The GPL v.3 gives you “legal permission to copy, distribute and/or modify”.

It’s best practice to have an unambiguous LICENSE or COPYING file which lays out these rights.

How do i

How do configure the expected host? For example, how would I set this to expect traffic from www.example.com?

SSL port?

I don't see the SSL port (443) being EXPOSEd. Is there a reason that it's not?

PHP Support

Hi,

Is it possible at the moment to serve PHP site with this image?

I have NGINX config like this:

server {
	listen 8006;
	server_name _;

	root /location/;
	index index.php index.html index.htm default.html default.htm;

	client_max_body_size 100M;
	
	location / {
		try_files $uri $uri/ /index.php?$args;
	}

	# deny running scripts inside writable directories
	location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
		return 403;
		error_page 403 /403_error.html;
	}
	
	location ~ \.php$ {
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include /etc/nginx/fastcgi_params;
	}
	
	# caching of files
	location ~* \.(ico|pdf|flv)$ {
		expires 1y;
	}

	location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
		expires 14d;
	}
}

When I run the container, it does not seem to work. Does not even print logs.

custom config overwritten after build

Hi there,

I am trying to create my own image with my own nginx conf file to enable basic auth. So:

FROM kyma/docker-nginx

COPY nginx/htpasswd /etc/nginx/.htpasswd
COPY nginx/default /etc/sites-enabled/default

WORKDIR /var/www

COPY . /var/www

EXPOSE 8080

CMD 'nginx'

but after built, in /etc/sites-enabled/default is always the same default file, not the mine :(

Support single page applications

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to redirecting to index.html
        try_files $uri $uri/ @root;
    }

    # If nginx can't find a file, fallback to the homepage.
    location @root {
        rewrite .* / redirect;
    }

The fallback is not actually redirecting to index.html. This is actually sending a 302 to the root.
I have not tested this yet, but I think we need to say

try_files $uri $uri/ /index.html;

[emerg] 1#0: "daemon" directive is duplicate in /etc/nginx/nginx.conf:21

When I run /usr/bin/docker run -it kyma/docker-nginx, I get:

thomasshanks@hostname ~ $ /usr/bin/docker run -it kyma/docker-nginx
2015/08/21 04:36:34 [emerg] 1#0: "daemon" directive is duplicate in /etc/nginx/nginx.conf:21
nginx: [emerg] "daemon" directive is duplicate in /etc/nginx/nginx.conf:21

I'm running on CoreOS stable (717.3.0).

Log files?

Where are the log files being sent to? I don't see them configured, so I'm assuming they're just going to /logs ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.