2015-07-01 13:57:52 +02:00
|
|
|
nginx
|
|
|
|
=====
|
|
|
|
|
2016-02-24 05:23:49 +02:00
|
|
|
![](https://badge.imagelayers.io/vimagick/nginx:latest.svg)
|
|
|
|
|
|
|
|
[Nginx][1] is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and
|
2015-07-01 13:57:52 +02:00
|
|
|
IMAP protocols, as well as a load balancer, HTTP cache, and a web server
|
|
|
|
(origin server).
|
|
|
|
|
2015-12-04 13:50:20 +02:00
|
|
|
## Static Website
|
|
|
|
|
2016-02-24 05:23:49 +02:00
|
|
|
File: docker-compose.yml
|
2015-07-01 13:57:52 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
nginx:
|
|
|
|
image: vimagick/nginx
|
|
|
|
ports:
|
|
|
|
- "80:80"
|
|
|
|
volumes:
|
2015-12-04 13:50:20 +02:00
|
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
|
|
|
|
- ./html:/usr/share/nginx/html
|
|
|
|
restart: always
|
|
|
|
```
|
|
|
|
|
|
|
|
## Website Proxy
|
|
|
|
|
2016-02-24 05:23:49 +02:00
|
|
|
File: docker-compose.yml
|
2015-12-04 13:50:20 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
nginx:
|
|
|
|
image: nginx:latest
|
|
|
|
volumes:
|
|
|
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
|
|
|
|
- ./nginx/sites-enabled/default:/etc/nginx/sites-enabled/default
|
|
|
|
- ./nginx/htpasswd:/etc/nginx/htpasswd
|
|
|
|
net: host
|
2015-07-01 13:57:52 +02:00
|
|
|
restart: always
|
|
|
|
```
|
2015-12-04 13:50:20 +02:00
|
|
|
|
|
|
|
> Password file can be generated by:
|
|
|
|
>> `htpasswd -b -c ./nginx/htpasswd username password`
|
|
|
|
|
2016-02-24 05:23:49 +02:00
|
|
|
File: nginx.conf
|
2015-12-04 13:50:20 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
user nginx;
|
|
|
|
worker_processes 4;
|
|
|
|
|
|
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
pid /var/run/nginx.pid;
|
|
|
|
|
|
|
|
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
http {
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
default_type application/octet-stream;
|
|
|
|
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
|
|
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
|
|
|
|
sendfile on;
|
|
|
|
#tcp_nopush on;
|
|
|
|
|
|
|
|
keepalive_timeout 65;
|
|
|
|
|
|
|
|
#gzip on;
|
|
|
|
|
|
|
|
include /etc/nginx/conf.d/*.conf;
|
|
|
|
include /etc/nginx/sites-enabled/*;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-02-24 05:23:49 +02:00
|
|
|
File: default
|
2015-12-04 13:50:20 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
server {
|
|
|
|
listen 80 default;
|
|
|
|
server_name _;
|
|
|
|
return 301 http://blog.foobar.site/;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
2016-05-01 03:06:20 +02:00
|
|
|
server_name blog.foobar.site blog.easypi.info;
|
2015-12-04 13:50:20 +02:00
|
|
|
location / {
|
|
|
|
proxy_pass http://127.0.0.1:6109;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
2016-05-01 03:06:20 +02:00
|
|
|
server_name wiki.foobar.site wiki.easypi.info;
|
2015-12-04 13:50:20 +02:00
|
|
|
location / {
|
|
|
|
auth_basic restricted;
|
|
|
|
auth_basic_user_file /etc/nginx/htpasswd;
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
2016-05-01 03:06:20 +02:00
|
|
|
server_name iot.foobar.site iot.easypi.info;
|
2015-12-04 13:50:20 +02:00
|
|
|
location / {
|
|
|
|
proxy_pass http://127.0.0.1:1880;
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2016-02-24 05:23:49 +02:00
|
|
|
|
|
|
|
File: [rtmp][1]
|
|
|
|
|
|
|
|
```
|
|
|
|
rtmp {
|
|
|
|
server {
|
|
|
|
listen 1935;
|
|
|
|
application live {
|
|
|
|
live on;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
[1]: http://nginx.org/
|
|
|
|
[2]: https://github.com/arut/nginx-rtmp-module/wiki/Directives
|