阿里云docker部署nginx并且配置ssl

1、本地創(chuàng)建nginx掛載路徑

mkdir /usr/local/docker/nginx/conf
mkdir /usr/local/docker/nginx/conf/conf.d
mkdir /usr/local/docker/nginx/html
mkdir /usr/local/docker/nginx/conf

2势就、簡單啟動一個nginx服務(wù)(僅用來復(fù)制配置文件纸厉,復(fù)制完即刪除此容器)

docker run --name nginx_test -d -p 80:80 nginx

3系吭、復(fù)制nginx配置文件到宿主機(jī)

docker cp my_nginx :/etc/nginx/conf.d /usr/local/docker/nginx/conf/conf.d/
docker cp my_nginx :/etc/nginx/nginx.conf  usr/local/docker/nginx/conf/
docker cp my_nginx :/usr/share/nginx/html/ /usr/local/docker/nginx/html/

進(jìn)去容器創(chuàng)建一個ssl文件夾用于存放ssl證書
#進(jìn)入 前面的 my_nginx 容器   
docker exec -it my_nginx /bin/bash
cd etc/nginx
touch ssl  #創(chuàng)建文件夾
docker cp my_nginx:/etc/nginx/ssl  /usr/local/docker/nginx/ssl

4、移除容器

docker rm -f my_nginx 

5颗品、掛載nginx.conf到宿主機(jī)

這里一定要在容器里面開啟443端口 阿里云也要開放443端口

docker run --name my_nginx -p 80:80 -p 443:443  -v /usr/local/docker/nginx/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx/html/:/usr/share/nginx/html/ -v /usr/local/docker/nginx/logs/:/var/log/nginx/ -v /usr/local/docker/nginx/ssl:/etc/nginx/ssl  --privileged=true -d --restart=always nginx
##這里一定要在容器里面開啟443端口  阿里云也要開放443端口

6肯尺、nginx.conf配置文件

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

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
  
    server {
        listen       80;
        server_name  xianzhuhz.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        keepalive_timeout  100;  #這個參數(shù)表示http連接超時時間,默認(rèn)是65s
        client_max_body_size 100m;         #主要是這個參數(shù)躯枢,限制了上傳文件大大小
        rewrite ^(.*)$ https://$host$1; #將所有HTTP請求通過rewrite指令重定向到HTTPS则吟。
         location /static { 
         root   /usr/share/nginx/html;
         index  index.html index.htm;
         }
         location / {
             proxy_pass  http://47.92.0.42:8085/hello;
                
         }
        
        #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   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;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
   server {
       listen       443 ssl;
       server_name  xianzhuhz.com;
        keepalive_timeout  100;  #這個參數(shù)表示http連接超時時間,默認(rèn)是65s
        client_max_body_size 100m;         #主要是這個參數(shù)锄蹂,限制了上傳文件大大小
         ssl_certificate      /etc/nginx/ssl/www.xianzhuhz.com.pem;
         ssl_certificate_key  /etc/nginx/ssl/www.xianzhuhz.com.key;
        
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         ssl_session_cache    shared:SSL:1m;
         ssl_session_timeout  5m;
         ssl_protocols TLSv1.1 TLSv1.2; 
         ssl_prefer_server_ciphers on;
         location /static { 
         root   /usr/share/nginx/html;
         index  index.html index.htm;
         }
         location / {
             proxy_pass  http://47.92.0.42:8085/hello;
                
         }      
    }
}

對應(yīng)上面的地址

 location /static { 
         root   /usr/share/nginx/html;
         index  index.html index.htm;
         }
image.png
image.png
image.png

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末逾滥,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌寨昙,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件掀亩,死亡現(xiàn)場離奇詭異舔哪,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)槽棍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門捉蚤,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人炼七,你說我怎么就攤上這事缆巧。” “怎么了豌拙?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵陕悬,是天一觀的道長。 經(jīng)常有香客問我按傅,道長捉超,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任唯绍,我火速辦了婚禮拼岳,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘况芒。我一直安慰自己惜纸,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布绝骚。 她就那樣靜靜地躺著耐版,像睡著了一般。 火紅的嫁衣襯著肌膚如雪皮壁。 梳的紋絲不亂的頭發(fā)上椭更,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天,我揣著相機(jī)與錄音蛾魄,去河邊找鬼虑瀑。 笑死,一個胖子當(dāng)著我的面吹牛滴须,可吹牛的內(nèi)容都是我干的舌狗。 我是一名探鬼主播,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼扔水,長吁一口氣:“原來是場噩夢啊……” “哼痛侍!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤主届,失蹤者是張志新(化名)和其女友劉穎赵哲,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體君丁,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡枫夺,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了绘闷。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片橡庞。...
    茶點故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖印蔗,靈堂內(nèi)的尸體忽然破棺而出扒最,到底是詐尸還是另有隱情,我是刑警寧澤华嘹,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布吧趣,位于F島的核電站,受9級特大地震影響除呵,放射性物質(zhì)發(fā)生泄漏再菊。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一颜曾、第九天 我趴在偏房一處隱蔽的房頂上張望纠拔。 院中可真熱鬧,春花似錦泛豪、人聲如沸稠诲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽臀叙。三九已至,卻和暖如春价卤,著一層夾襖步出監(jiān)牢的瞬間劝萤,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工慎璧, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留床嫌,地道東北人。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓胸私,卻偏偏與公主長得像厌处,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子岁疼,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,601評論 2 353

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