使用Docker搭建Nginx

一、新建nginx.conf

以下是转发Wordpress网站配置示例

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #access_log  logs/host.access.log  main;

    server {
        listen 80;
        server_name litchise.club www.litchise.club;
        return 301 https://litchise.club$request_uri;
    }

    server {
        listen 443 ssl http2;
        server_name litchise.club;
        client_max_body_size 64M;
        ssl_certificate /etc/nginx/cert/litchise.club/litchise.club.pem;
        ssl_certificate_key /etc/nginx/cert/litchise.club/litchise.club.key;
        #ssl_verify_client on;
        ssl_session_timeout 5m;
        ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers on;
        location  / {
            proxy_set_header Host $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header Cookie $http_cookie;
            add_header Content-Security-Policy upgrade-insecure-requests;
            proxy_pass http://127.0.0.1:8081/;
        }
    }
}

二、安装Nginx

docker run --privileged=true --restart=always --net=host --name nginx \
-v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /root/nginx/html/:/etc/nginx/html:ro \
-v /root/nginx/cert/:/etc/nginx/cert \
-d nginx

留下评论