7用踩、Ubuntu docker 安裝ngnix

1悼潭、創(chuàng)建映射目錄

mkdir -p /docker/nginx/{conf,conf.d,www,log,html,letsencrypt,cert}

2潮酒、創(chuàng)建網(wǎng)絡(luò)壞境

docker network create --driver=bridge --subnet=192.168.88.0/24? cidi

3、創(chuàng)建docker-compose.yml

cat > /docker/nginx/docker-compose.yml << EOF

version: "3"

services:

? nginx:

? ? image: nginx:latest

? ? container_name: nginx

? ? restart: always

? ? ports:

? ? ? - "80:80"

? ? ? - "433:433"

? ? volumes:

? ? ? - /docker/nginx/conf:/etc/nginx/conf

? ? ? - /docker/nginx/conf.d:/etc/nginx/conf.d

? ? ? - /docker/nginx/log:/var/log/nginx

? ? ? - /docker/nginx/www:/var/www

? ? ? - /docker/nginx/letsencrypt:/etc/letsencrypt

? ? ? - /docker/nginx/html:/usr/share/nginx/html

? ? ? - /docker/nginx/cert:/etc/nginx/cert

? ? networks:

? ? ? - cidi

? ? ? ? #ipv4_address: 192.169.0.3

networks:

? cidi:

? ? external: true

? ? ? #driver: bridge

? ? ? #ipam:

? ? ? ? #config:

? ? ? ? ? ? #- subnet: 10.10.0.0/16

EOF

4磨镶、 配置nginx 主配置

cat >? /docker/nginx/conf/nginx.conf << EOF

user? nginx;

worker_processes? 1;

error_log? /var/log/nginx/error.log warn;

pid? ? ? ? /var/run/nginx.pid;

events {

? ? worker_connections? 1024;

}

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

? ? access_log? /var/log/nginx/access.log? main;

? ? sendfile? ? ? ? on;

? ? #tcp_nopush? ? on;

? ? keepalive_timeout? 65;

? ? #gzip? on;

? ? include /etc/nginx/conf.d/*.conf;

}

EOF

5枷遂、默認(rèn)配置設(shè)置

cat > /docker/nginx/conf.d/default.conf << EOF

server {

? ? listen? ? ? 80;

? ? #server_name? localhost;

? ? #charset koi8-r;

? ? #access_log? /var/log/nginx/log/host.access.log? main;

? ? location / {

? ? ? ? root? /var/www;

? ? ? ? index? index.html index.htm;

? ? ? ? autoindex? on;

? ? }

? ? location /jenkins {

? ? ? ? ? ? proxy_pass http://jenkins:8080/jenkins;

? ? ? ? ? ? #proxy_set_header Host $host;

? ? ? ? ? ? #proxy_set_header X-Real-IP $remote_addr;

? ? ? ? ? ? #proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;

? ? ? ? }

? ? #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;

? ? }

? ? # proxy the PHP scripts to Apache listening on 127.0.0.1:80

? ? #

? ? #location ~ \.php$ {

? ? #? ? proxy_pass? http://127.0.0.1;

? ? #}

? ? # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

? ? #

? ? #location ~ \.php$ {

? ? #? ? root? ? ? ? ? html;

? ? #? ? fastcgi_pass? 127.0.0.1:9000;

? ? #? ? fastcgi_index? index.php;

? ? #? ? fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;

? ? #? ? include? ? ? ? fastcgi_params;

? ? #}

? ? # deny access to .htaccess files, if Apache's document root

? ? # concurs with nginx's one

? ? #

? ? #location ~ /\.ht {

? ? #? ? deny? all;

? ? #}

}

EOF

6、運行?

docker-compose up -d

7棋嘲、測試,測試404的話矩桂,需要在自己創(chuàng)建的www文件夾增加index.html

curl localhost??

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末沸移,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子侄榴,更是在濱河造成了極大的恐慌雹锣,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件癞蚕,死亡現(xiàn)場離奇詭異蕊爵,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)桦山,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門攒射,熙熙樓的掌柜王于貴愁眉苦臉地迎上來醋旦,“玉大人,你說我怎么就攤上這事会放∷瞧耄” “怎么了?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵咧最,是天一觀的道長捂人。 經(jīng)常有香客問我,道長矢沿,這世上最難降的妖魔是什么滥搭? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮捣鲸,結(jié)果婚禮上瑟匆,老公的妹妹穿的比我還像新娘。我一直安慰自己摄狱,他們只是感情好脓诡,可當(dāng)我...
    茶點故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著媒役,像睡著了一般祝谚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上酣衷,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天交惯,我揣著相機(jī)與錄音,去河邊找鬼穿仪。 笑死席爽,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的啊片。 我是一名探鬼主播只锻,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼紫谷!你這毒婦竟也來了齐饮?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤笤昨,失蹤者是張志新(化名)和其女友劉穎祖驱,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體瞒窒,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡捺僻,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片匕坯。...
    茶點故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡束昵,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出醒颖,到底是詐尸還是另有隱情妻怎,我是刑警寧澤,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布泞歉,位于F島的核電站逼侦,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏腰耙。R本人自食惡果不足惜榛丢,卻給世界環(huán)境...
    茶點故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望挺庞。 院中可真熱鬧晰赞,春花似錦、人聲如沸选侨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽援制。三九已至戏挡,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間晨仑,已是汗流浹背褐墅。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留洪己,地道東北人妥凳。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像答捕,于是被迫代替她去往敵國和親逝钥。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容