Docker安装Redmine并使用Nginx反向代理为https

1.部署docker环境

安装后最好配置为国内源,此步略过,网上教程很多。

2.部署数据库环境

这里直接使用宿主机内现有的mysql数据库,就不用再安装了。

使用以下sql语句创建数据库和数据库用户。

CREATE DATABASE IF NOT EXISTS redmine DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'redmine'@'172.17.0.%' IDENTIFIED BY '123456';
GRANT all privileges ON redmine.* TO 'redmine'@'172.17.0.%';
FLUSH PRIVILEGES;

3.安装redmine容器

mkdir -p /data/redmine/files
docker run --name redmine -d \
-p 12000:3000 \
-v /data/redmine/files:/usr/src/redmine/files:z \
-e REDMINE_DB_MYSQL=172.17.0.1 \
-e REDMINE_DB_PORT=3306 \
-e REDMINE_DB_DATABASE=redmine \
-e REDMINE_DB_USERNAME=redmine \
-e REDMINE_DB_PASSWORD=123456 \
-e TZ="Asia/Shanghai" \
--restart=always \
redmine:4.1.0

其中12000端口可以自己指定,为宿主机的端口,映射到容器的3000端口,容器的3000端口为redmine访问端口。

4.配置nginx反向代理

    server {
        listen 443 ssl;
        ssl on;
        server_name redmine.xxx.com;
        #配置ssl证书路径,自行设置
        ssl_certificate      /etc/letsencrypt/live/xxx.com/fullchain.pem;
        #配置ssl密钥路径,自行设置
        ssl_certificate_key  /etc/letsencrypt/live/xxx.com/privkey.pem;
        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;
        location / {
            proxy_pass http://127.0.0.1:12000/;
            client_max_body_size 100m;
            proxy_redirect off;
            #下面这一步一定要加上端口号,否则如果使用非443端口,网站在ajax请求之后会跳转到错误的页面(会不带端口号)
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $http_connection;
            proxy_http_version 1.1;
            #下面这一行配置也要加上,否则ajax请求之后会跳转到错误的页面(https会变成http)
            proxy_set_header X-Forwarded-Proto $scheme;
            index index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

 

 

你可能感兴趣的:(运维)