Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx SSL inside a docker container

Tags:

I have configured a Docker container to run Nginx and setup the /etc/nginx/sites-available/default file as shown below

server  {  listen 80 default_server;  listen [::]:80 default_server ipv6only=on;   root /usr/share/nginx/html;  index index.php index.html index.htm;   server_name example.com;   location / {             try_files $uri $uri/ /index.html;     }      error_page 404 /404.html;      error_page 500 502 503 504 /50x.html;     location = /50x.html {           root /usr/share/nginx/html;     }       location ~ \.php$ {         try_files $uri =404;         fastcgi_split_path_info ^(.+\.php)(/.+)$;     fastcgi_pass unix:/var/run/php5-fpm.sock;     fastcgi_index index.php;             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;            include fastcgi_params;  }  }  server  {  listen 443;   root /usr/share/nginx/html;  index index.php index.html index.htm;   server_name example.com;   ssl    on;  ssl_certificate    /etc/ssl/certs/ssl-cert-snakeoil.pem;  ssl_certificate_key    /etc/ssl/private/ssl-cert-snakeoil.key;    location / {             try_files $uri $uri/ /index.html;     }      error_page 404 /404.html;      error_page 500 502 503 504 /50x.html;     location = /50x.html {           root /usr/share/nginx/html;     }   location ~ \.php$ {         try_files $uri =404;         fastcgi_split_path_info ^(.+\.php)(/.+)$;     fastcgi_pass unix:/var/run/php5-fpm.sock;     fastcgi_index index.php;             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;            include fastcgi_params;  }   } 

I map the /etc/ssl/certs & /etc/ssl/private folders on the host when I run the docker container

docker run -dt -p 8080:443 -p 8081:80 -v /t-base/log:/var/log/nginx -v /etc/ssl/certs:/etc/ssl/certs -v /etc/ssl/private:/etc/ssl/private nginx  Docker ps shows  Up n minutes 0.0.0.0:8081->80/tcp 0.0.0.0:8080->443/tcp <container-name> 

and the nginx error log file inside the mapped /t-base/log folder stays empty.

docker exec -it <container-name> /bin/bash 

followed by

service nginx status 

just comes back and says that nginx is running.

All of the above would indicate that everything is working correctly. However, I find that whilst I am able to browse to

http://example.com:8080 

turns up the default page

https://example.com:8081 

has the Chrome showing me its default "sad smiley" error page. I cannot see what I might be doing wrong here. I'd much appreciate any help.

like image 301
DroidOS Avatar asked Jan 13 '15 11:01

DroidOS


People also ask

Should nginx be in a container?

nginx:<version>It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.


1 Answers

You have interchanged the ports. According to this command line -p 8080:443 -p 8081:80, you should do:

https://example.com:8080 note this is https

and

http://example.com:8081

This should work

like image 199
vanthome Avatar answered Sep 17 '22 22:09

vanthome