docker-compose部署nginx教程
docker-compose部署nginx
安裝docker-compose
創(chuàng)建nginx文件夾
添加docker-compose.yml文件:
version: '3.3'
services:
web:
image: "xtulnx/nginx:tengine-latest"
container_name: nginx
hostname: s.nginx
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./html:/etc/nginx/html
- ./data:/data
- ./logs:/etc/nginx/logs
# 配置轉(zhuǎn)發(fā)時(shí)可直接寫(xiě) proxy:s.dev
extra_hosts:
- "s.host:170.170.0.1"
- "s.dev:127.0.0.1"
working_dir: /etc/nginx
ports:
- "80:80"
- "443:443"
environment:
- NGINX_PORT=80
restart: always
在當(dāng)前文件下添加volumes中映射的文件夾
conf.d文件下的default.conf
log_format custom_log '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_body $query_string '
'"$http_user_agent" "$http_x_forwarded_for" "$request_uri" '
'proxy_to: $upstream_addr';
log_format httplog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" $request_body $query_string'
'"$http_user_agent" "$http_x_forwarded_for" "$request_uri"';
log_format uplg '$remote_addr - $remote_user [$time_local] [$upstream_addr] "$request" [$request_body]'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format hu '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$gzip_ratio" $request_time $bytes_sent $request_length' ' $request_body';
access_log logs/access.log custom_log;
# sendfile on;
#增加一下websocket配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
#創(chuàng)建de
include conf.d/*.conf;
location / {
# root /usr/share/nginx/html;
root /etc/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}自定義的一些轉(zhuǎn)發(fā)配置文件例子:
- user.conf
#重寫(xiě)路徑的例子
#rewrite ^/dev_user/(.*\.*)$ /user/$1;
location ^~/user/ {
#s.dev是nginx的compose里面配置的
proxy_pass http://s.dev:8080/user/;
#proxy_pass http://10.22.22.22:8080/user/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}配置生效重啟
- 可寫(xiě)成reload.sh:
docker-compose exec web nginx -s reload #注:exec 正在運(yùn)行的容器中執(zhí)行命令:nginx -s reload
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
docker-compose中的環(huán)境變量問(wèn)題
這篇文章主要介紹了docker-compose中的環(huán)境變量問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
修改Docker默認(rèn)鏡像和容器的存儲(chǔ)位置的方法
本篇文章主要介紹了修改Docker默認(rèn)鏡像和容器的存儲(chǔ)位置的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
一臺(tái)虛擬機(jī)基于docker搭建大數(shù)據(jù)HDP集群的思路詳解
這篇文章主要介紹了一臺(tái)虛擬機(jī)基于docker搭建大數(shù)據(jù)HDP集群?,本篇文章主要講了大數(shù)據(jù)集群搭建的架構(gòu)設(shè)計(jì)和實(shí)現(xiàn)思路部分,后面文章會(huì)探討上層應(yīng)用的構(gòu)建,需要的朋友可以參考下2022-11-11
基于docker?部署canvas-lms的詳細(xì)步驟
這篇文章主要介紹了基于docker?部署?canvas-lms,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03
docker文件存放路徑, 獲取容器啟動(dòng)命令操作
這篇文章主要介紹了docker文件存放路徑, 獲取容器啟動(dòng)命令操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
Docker 容器互聯(lián)互通的實(shí)現(xiàn)方法
這篇文章主要介紹了Docker 容器互聯(lián)互通,本文講解不同網(wǎng)絡(luò)下的容器可以通過(guò)加入同一個(gè)docker網(wǎng)絡(luò),來(lái)訪問(wèn)該docker網(wǎng)絡(luò)下的容器,并且既可以通過(guò)容器ip也可以通過(guò)容器名連接,非常方便,需要的朋友可以參考下2022-10-10

