Docker安装Nginx

admin
2022-02-27 / 0 评论 / 312 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年03月11日,已超过985天没有更新,若内容或图片失效,请留言反馈。

一、Docker安装Nginx

  1. 拉取Nginx镜像

    docker pull nginx:1.10
  2. 随便启动一个nginx 实例,只是为了复制出配置

    docker run -p 80:80 --name nginx -d nginx:1.10
  3. 拷贝容器内的配置文件

    docker container cp nginx:/etc/nginx .
  4. 重命名文件夹

    mv nginx conf 
  5. 移动配置文件到/mydata/nginx下

    mv conf /mydata/nginx/
  6. 终止原容器

    docker stop nginx
  7. 删除原容器

    docker rm nginx
  8. 运行Nginx容器,参数见-说明1

    docker run -d -p 80:80 -p 443:443 --name nginx -v /mydata/nginx/html:/var/www/html -v /mydata/nginx/conf/conf.d:/etc/nginx/conf.d -v /mydata/nginx/logs:/var/log/nginx --link php:phpfpm --name nginx nginx:1.10
  9. 设置随Docker启动

    docker update --restart=always nginx

二、Nginx配置

https协议SSL-443配置,在/mydata/nginx/conf/conf.d下新建配置文件yanxizhu.com.conf,内容如下:

server {
    listen 443 ssl http2 reuseport;
    server_name yanxizhu.com  www.yanxizhu.com;
    root /var/www/html/yanxizhu.com;
    index index.php;
    
    ssl on;
    ssl_certificate /etc/nginx/conf.d/自己证书.crt;
    ssl_certificate_key /etc/nginx/conf.d/自己证书key.key;
    ssl_session_cache shared:SSL:1m;
    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;

    access_log /var/log/nginx/typecho_access.log main;

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }

    location ~ .*\.php(\/.*)*$ {
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        fastcgi_pass   phpfpm:9000;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
    }
}
server {
    listen       80;
    server_name  yanxizhu.com  www.yanxizhu.com;
    rewrite ^(.*) https://yanxizhu.com$1 permanent;
}

注意:映射路径、文件存放路径、证书路径。https://www.yanxizhu.com/ 博客SSL配置如上,使用的mysql、php、nginx、typecho搭建。

7

评论 (0)

取消