標籤:滑鼠 sha 解析 png mat image debug contain fun
每天學習一點點 編程PDF電子書、視頻教程免費下載: http://www.shitanlife.com/code
一. 下載並安裝Nginx
去Nginx官網下載
我這裡選取nginx/Windows-1.10.3版本,下載後解壓出來即可,解壓出來的路徑不能含有中文
我解壓後將其放置的路徑如下
二、開始運行
在目前的目錄下按住shift+滑鼠右鍵,選擇“在此處開啟命令視窗”,然後輸入start nginx
此時,就可以進入瀏覽器輸入訪問地址,http://127.0.0.1/或者http://localhost/即可訪問
三、設定檔講解
核心設定檔就是nginx.conf,該檔案位於conf目錄下,大部分情況下我們就是修改該檔案的配置
該檔案的原始配置如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
#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 localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root 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 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 localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } |
其中#代表注釋
nginx我們最主要的作用是拿來做反向 Proxy和負載平衡,這個我後面會著重講解。同時它還是一個web伺服器,與我們常用的Apache、tomcat、IIS一樣,也可以用來託管web服務。
本章先暫時介紹下該設定檔中的幾個重要參數,後面會對nginx部署php和Python項目再進行著重講解,至於java的項目通常是tomcat+nginx同時進行配置,nginx用來做負載平衡和處理靜態頁。
1、定義Nginx啟動並執行使用者和使用者組
2、nginx進程數,建議設定為等於CPU總核心數
3、全域錯誤記錄檔定義類型,[ debug | info | notice | warn | error | crit ]
12 |
#error_log logs/error.log notice; #error_log logs/error.log info; |
4、進程檔案
5、工作模式與串連數上限:worker_connections是單個後台worker process進程的最大並發連結數,並發總數是 worker_processes 和 worker_connections 的乘積, 即 max_clients = worker_processes * worker_connections
123 |
events { worker_connections 1024; } |
6、http下的一些配置及其意義
12345678 |
include mime.types; #副檔名與檔案類型映射表 default_type application /octet-stream ; #預設檔案類型 sendfile on; #開啟高效檔案傳輸模式,sendfile指令指定nginx是否調用sendfile函數來 輸出檔案,對於普通應用設為 on,如果用來進行下載等應用磁碟IO重負載應用,可設定 為off,以平衡磁碟與網路I/O處理速度,降低系統的負載。注意:如果圖片顯示不正常 把這個改成off。 autoindex on; #開啟目錄列表訪問,合適下載伺服器,預設關閉。 tcp_nopush on; #防止網路阻塞 tcp_nodelay on; #防止網路阻塞 keepalive_timeout 120; #長連線逾時時間,單位是秒 gzip on; #開啟gzip壓縮輸出 |
7、server虛擬機器主機的相關配置
我們平時配置各類伺服器,配置最多的就是這些地方了
比如:
123456789101112131415161718192021 |
http{ #虛擬機器主機1 server{ listen 80; #監聽連接埠,基於IP配置的時候變更此處,比如192.168.1.100:8080; server_name www.xdw.com; #主機網域名稱,實際項目發布的話,填公網上的網域名稱,本地部署的話,可以在C:\Windows\System32\drivers\etc\hosts檔案中添加IP和網域名稱的映射 location / { #映射解析,/代表根路徑,此處解析還有Regex的解析方式,具體請參考http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#location root E: /xdw/0221 ; #工程所在路徑 index index.html index.htm; #首頁(預設頁) } } #虛擬機器主機2,可以同時配置多個虛擬機器主機 server{ listen 8080; server_name localhost; location / { root D: /xiangmu/txym_web ; index index.html index.htm; } } } |
看到這個虛擬機器主機的配置,相信配置過tomcat或者Apache的人都很熟悉的感覺。此篇就到此結束,下面還會更新linux下的配置,php和python項目的部署,反向 Proxy和負載平衡,配合tomcat部署java項目。
Nginx在windows環境下的安裝與簡單配置