天天看點

docker安裝nginx

1.查找鏡像

docker search nginx

docker安裝nginx

2.拉取鏡像

docker pull nginx

docker安裝nginx

3.建立挂載目錄

mkdir conf

mkdir develop

ls

docker安裝nginx

4.進入conf目錄,建立nginx.conf配置檔案

# gzip設定

gzip on;

gzip_vary on;

gzip_comp_level 6;

gzip_buffers 16 8k;

gzip_min_length 1000;

gzip_proxied any;

gzip_disable "msie6";

#gzip_http_version 1.0;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

server {

    listen       80;

    server_name  localhost;

    #charset koi8-r;

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

    #location / {

        #root   /usr/share/nginx/html;

        #index  index.html index.htm;

        # 其作用是按順序檢查檔案是否存在,傳回第一個找到的檔案或檔案夾(結尾加斜線表示為檔案夾),如果所有的檔案或檔案夾都找不到,會進行一個内部重定向到最後一個參數。

        #try_files $uri /index.html;

    #}

    location / {

        root    /usr/share/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;

    # 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

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

}

5.啟動容器

docker run --name nginx -p 80:80 --privileged=true -v /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/conf.d/default.conf -v /usr/local/docker/nginx/develop/dist/:/usr/share/nginx/html/ -d nginx

docker安裝nginx

繼續閱讀