-
準(zhǔn)備工作
(1)確保已安裝docker和nginx
(2)簽名文件
(3)域名
創(chuàng)建nginx映射文件逗抑、目錄
mkdir /root/docker-nginx
//存放nginx配置文件
mkdir /root/docker-nginx/conf.d
//存放nginx日志(方便查錯(cuò))
mkdir /root/docker-nginx/logs
//存放簽名文件
mkdir /root/docker-nginx/ssl
//項(xiàng)目
mkdir /root/docker-nginx/www
- 在/root/docker-nginx/www 目錄下創(chuàng)建個(gè)index.html文件逛腿,方便查看結(jié)果
cd /root/docker-nginx/www
vim index.html
index.html 頁面內(nèi)容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<h1>恭喜你惰蜜,配置成功钮蛛!</h1>
</body>
</html>
在/root/docker-nginx/ssl目錄下存放你的簽名證書
在/root/docker-nginx下創(chuàng)建nginx默認(rèn)配置文件
cd /root/docker-nginx
vim nginx.conf
下面是nginx提供的默認(rèn)配置
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
上面配置include /etc/nginx/conf.d/*.conf;這行可知鞭缭,文件會(huì)包含conf.d目錄下的所有.conf后綴的配置文件,所以我們只需要在conf.d目錄下創(chuàng)建自己的配置文件即可愿卒。
- 在 /root/docker-nginx/conf.d 目錄下創(chuàng)建default.conf配置文件
cd /root/docker-nginx/conf.d
vim default.conf
內(nèi)容如下
server {
listen 80;
server_name 你的域名;
#轉(zhuǎn)發(fā)到http
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name 你的域名;
root /usr/share/nginx/html;
index index.html index.htm;
ssl_certificate /root/ssl/你的證書.pem;
ssl_certificate_key /root/ssl/你的證書.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
}
- 啟動(dòng)nginx容器
docker run -d \
-p 80:80 -p 443:443\
-v /root/docker-nginx/conf.d:/etc/nginx/conf.d:ro \
-v /root/docker-nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /root/docker-nginx/logs:/var/log/nginx \
-v /root/docker-nginx/www:/usr/share/nginx/html \
-v /root/docker-nginx/ssl:/root/ssl \
--name nginx \
nginx:latest
==特別注意:這里需要把443端口也映射出去==
寫在最后:
以上只說明了nginx的一些相關(guān)配置缚去。還有些其他配置需要注意,比如linux開發(fā)端口琼开。如果是阿里云服務(wù)器易结,還需要在安全組開放端口