nginx簡介
Nginx是一款面向性能設計的HTTP服務器,相較于Apache、lighttpd具有占有內存少,穩定性高等優勢。與舊版本(<=2.2)的Apache不同,nginx不采用每客戶機一線程的設計模型,而是充分使用異步邏輯,削減了上下文調度開銷,所以并發服務能力更強。整體采用模塊化設計,有豐富的模塊庫和第三方模塊庫,配置靈活。 在Linux操作系統下,nginx使用epoll事件模型,得益于此,nginx在Linux操作系統下效率相當高。同時Nginx在OpenBSD或FreeBSD操作系統上采用類似于epoll的高效事件模型kqueue。
docker hub拉取
docker hub 是docker官方的鏡像源,里面有做好的nginx docker image,當然也可以發布自己的鏡像到上面去。
如果官方鏡像速度很慢,可以考慮用
阿里云的docker鏡像倉庫
主要步驟如下:
登錄阿里云的docker鏡像倉庫
獲取專屬加速器地址
升級docker客戶端(建議在1.6.0以上)
修改daemon配置文件(阿里已經給出了所有的命令,基本上只要copy paste即可)
然后使用
docker pull nginx
就可以快速下載官方的nginx docker image了。
基礎的docker命令可以參看Docker初體驗
Nginx docker image
在docker官方的頁面上,有部分樣例的說明??梢园l現,網站的主目錄是 /usr/share/nginx/html ,這跟我搜到的一些文章的說明不同。
我的需求是實現nginx搭建的文件瀏覽站。說白了就是下載站。實驗室(or校園內)共享文件。原來采用的是 Python救急HttpServer和Ftpserver ,盡管后來采用了 python多線程啟動httpserver ,但還是經常因為卡線程的問題,導致地址訪問失敗。所以那個方法作為臨時應急工具還是可以的,但是如果想要長期共享文件,必須采用有完善功能的http server。
nginx的配置文件都在 /etc/nginx/ 下面,可以看到熟悉的 conf.d 文件夾,明顯里面是用戶自定義配置文件的位置。
修改自定義配置
default.conf文件內容如下:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; root /usr/share/nginx/html; location / { root /usr/share/nginx/html; index index.html index.htm; ## 下面三行是添加的。 autoindex on; autoindex_exact_size on; autoindex_localtime on; } #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; #}}
只需要完整的復制出來,并添加
autoindex on;autoindex_exact_size on;autoindex_localtime on;
新聞熱點
疑難解答