docker部署nginx

  1. 执行下列代码
home=/home/docker/config/nginx;
mkdir -p ${home}/conf;
mkdir -p ${home}/cert;
mkdir -p ${home}/logs;
mkdir -p ${home}/www;
touch ${home}/conf/nginx.conf;
touch ${home}/logs/error.log;
touch ${home}/logs/access.log;
chmod 777 ${home}/conf/nginx.conf;
chmod 777 ${home}/logs/error.log;
chmod 777 ${home}/logs/access.log;
chmod 777 ${home}/conf;
chmod 777 ${home}/cert;
chmod 777 ${home}/logs;
chmod 777 ${home}/www;
  1. 将下面复制进nginx.conf
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile  102400;

events {
        worker_connections  102400;
}


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" "$request_body"';

    access_log  /var/log/nginx/access.log  main;
	
	client_max_body_size 500m;  
	#nginx的默认配置,其client_header_buffer_size的默认值是1k
	client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
		
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  75;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
	proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=10g;
	
	
	#######################################xxxxxxxxx###########################################
	server {
    listen 9000;
    server_name  localhost;
    location / {
        root    /usr/share/nginx/html/lots;
        index   index.html index.htm;
        autoindex on;
        try_files $uri $uri/ /index.html =404;
    }
 
    location /api/ {
		proxy_redirect  off;  
        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 Cookie "$http_cookie; $request_body";
        proxy_pass http://localhost:8080/; #末尾加/请求为 localhost:8080/xxx 不加为localhost:8080/api/xxx
    }
	}
}
  1. 执行下列命令
home=/home/docker/config/nginx;
docker run --name nginx -d --restart=always --net=host -v ${home}/www:/usr/share/nginx/html:ro -v ${home}/logs:/var/log/nginx -v ${home}/conf/nginx.conf:/etc/nginx/nginx.conf -v ${home}/cert:/etc/nginx/cert -d --privileged=true  nginx:1.9.0;

–net=host 的含义是容器内的端口全部映射宿主机端口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值