首先去官網下載軟件包,解壓,路徑最好不要有中文
nginx配置的路徑問題
由于在windows下文件路徑可以用””, 也可以用””, 也可以用”/”作為路徑做分隔符。但””最容易引發問題,所以要盡量避免使用。
不要添加path,否則會引發錯誤,config文件路徑找不到
比如我解壓在e盤
cmd命令定位到nginx.exe所在文件夾cd e:worksoftware ginx-1.10.1
然后執行,首先保證nginx.conf文件配置沒問題
其實nginx最重要的和最主要的工作就是配置文件,其他沒什么需要我們應用開發人員關注的,除非想修改底層源碼.
nginx.conf配置如下:
#user?nobody;? worker_processes?1;? #工作進程的個數,可以配置多個? ? #全局錯誤日志及pid文件? error_log?/worksoftware/nginx-1.10.1/logs/error.log;? #error_log?logs/error.log?notice;? #error_log?logs/error.log?info;? ? pid??/worksoftware/nginx-1.10.1/logs/nginx.pid;? ? ? events?{? ?worker_connections?1024;?#單個進程最大連接數(最大連接數=連接數*進程數)? }? ? #設定http服務器,利用它的反向代理功能提供負載均衡支持? http?{? ?include??mime.types;?#設定配置文件位置,這里的conf是指nginx.conf所在的目錄,也可以用絕對路徑指定其他地方的配置文件? ?default_type?application/octet-stream;?#默認類型-8進制文件流? ? ?#設定日志格式? ?#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?/worksoftware/nginx-1.10.1/logs/access.log?main;? ? ?sendfile??on;?#是否激活sendfile()函數,比默認模式更有效率? ?#tcp_nopush??on;?#將http響應頭壓縮到一個包中發送,僅在sendfile開啟時才能配合使用? ? ?#連接超時時間? ?#keepalive_timeout?0;? ?keepalive_timeout?65;? ? ?gzip?on;?#啟用gzip壓縮? ? ?#服務器的集群? ?#設定負載均衡的服務器列表?支持多組的負載均衡,可以配置多個upstream?來服務于不同的server.? ?#nginx?的?upstream?支持?幾?種方式的分配? ?#1)、輪詢(默認)?每個請求按時間順序逐一分配到不同的后端服務器,如果后端服務器down掉,能自動剔除。? ?#2)、weight?指定輪詢幾率,weight和訪問比率成正比,用于后端服務器性能不均的情況。?跟上面樣,指定了權重。? ?#3)、ip_hash?每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個后端服務器,可以解決session的問題。? ?#4)、fair??? ?#5)、url_hash?#urlhash? ?? ?#upstream?imicrosoft.net? ?#{? ??#服務器集群名字? ??#服務器配置?weight是權重的意思,權重越大,分配的概率越大。? ??#server?192.98.12.60:1985?weight=3?max_fails=2?fail_timeout=30s;? ??#server?192.98.12.42:8086?weight=3?max_fails=2?fail_timeout=30s;? ??? ??#weigth參數表示權值,權值越高被分配到的幾率越大? ??#1.down?表示單前的server暫時不參與負載? ??#2.weight?默認為1.weight越大,負載的權重就越大。?? ??#3.backup:?其它所有的非backup機器down或者忙的時候,請求backup機器。所以這臺機器壓力會最輕。??? ??#本例是指在同一臺服務器,多臺服務器改變ip即可?? ?#?server?127.0.0.1:8055?weight=4?down;? ?#?server?127.0.0.1:8010?weight=5?backup;? ?#}? ?? ?? ?upstream?localhost? ?{?? ??server?127.0.0.1:9000?weight=3?max_fails=2?fail_timeout=200s;? ??server?127.0.0.1:8086?weight=5?max_fails=2?fail_timeout=200s;? ?}? ?? ?? ?#當前的nginx的配置,代理服務器的地址,即nginx安裝的服務器地址、監聽端口、默認地址,? ?#設定虛擬主機,默認為監聽80端口? ?server? ?{? ??listen??9090;?#偵聽9090端口? ??#對于server_name,如果需要將多個域名的請求進行反向代理,可以配置多個server_name來滿足要求? ??server_name?localhost;?#當前服務的域名? ??? ??charset?utf8;? ??#charset?koi8-r;? ?? ??#設定本虛擬主機的訪問日志? ??#access_log?logs/host.access.log?main;? ? ??? ??#如果訪問?/images/*,?/js/*,?/css/*?資源,則直接取本地文件,不用轉發。? ??#但如果文件較多效果不是太好。? ??#location?~?.*.(jpg|jpeg|gif|css|png|ico|html)$? ??#{? ??#?expires?30d;? ??#?root?/nginx-1.10.1;#root:? ??#?break;? ??#}? ??? ??#對?"/"?啟用負載均衡? ??location?/?{? ???? ???root?html;??#默認主頁目錄在nginx安裝目錄的html子目錄? ??? ???index?index.html?index.htm?index.aspx;?#沒有索引頁時,羅列文件和子目錄? ???#proxy_pass?http://www.imicrosoft.net;?#跟載均衡服務器的upstream對應????? ???autoindex?on;?#沒有索引頁時,羅列文件和子目錄? ??? ???#保留用戶真實信息? ???proxy_redirect?off;?#url不跳轉? ???proxy_set_header?host?$host;? ???proxy_set_header?x-real-ip?$remote_addr;? ???proxy_set_header?x-forwarded-for?$proxy_add_x_forwarded_for;? ???#緩沖區代理緩沖用戶端請求的最大字節數,可以理解為先保存到本地再傳給用戶? ???#?client_body_buffer_size?128k;? ???#?#跟后端服務器連接超時時間?發起握手等候響應超時時間? ???#?proxy_connect_timeout?12;? ???#?#連接成功后?等待后端服務器響應時間?其實已進入后端的排隊之中等候處理? ???#?proxy_read_timeout?90;? ???#?#代理請求緩存區?這個緩存區間會保存用戶的頭信息一共nginx進行規則處理?一般只要能保存下頭信息即可? ???#?proxy_send_timeout?90;? ???#?#同上?告訴nginx保存單個用的幾個buffer最大用多大空間? ???#?proxy_buffer_size?4k;? ???#?proxy_buffers?4?32k;? ???#?#如果系統很忙的時候可以申請國內各大的proxy_buffers?官方推薦?*2? ???#?proxy_busy_buffers_size?64k;? ???#?#proxy?緩存臨時文件的大小? ???proxy_temp_file_write_size?64k;? ???#?proxy_next_upstream?error?timeout?invalid_header?http_500?http_503?http_404;? ???proxy_max_temp_file_size?128m;? ???#啟動代理? ???proxy_pass?http://localhost;? ???client_max_body_size?10m;?#允許客戶端請求的最大單個文件字節數? ??}? ? ??? ??? ??#示例一? ??#location?/?{? ??#??proxy_pass?http://imicrosoft.net;? ??#?? ??#??proxy_redirect?default;? ??#??? ??#??proxy_set_header?host?$host;? ??#??proxy_set_header?x-forwarded-for?$proxy_add_x_forwarded_for;? ??#}? ??? ??#示例二? ??#location?/tileservice?{? ??#??proxy_pass?http://cluster/mongotileservice/tileservice;? ??#??proxy_set_header?host?$host;? ??#??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?html;? ??}? ? ??#?proxy?the?php?scripts?to?apache?listening?on?127.0.0.1:80? ??#對?"/xxxxx.php"?啟用負載均衡? ??#location?~?.php$?{? ??#?proxy_pass?http://127.0.0.1;? ??#}? ??? ??#location?/baidu? ??#{? ??#proxy_pass?http://www.google.com;? ??#proxy_set_header?host?$host;? ??#proxy_set_header?x-forwarded-for?$proxy_add_x_forwarded_for;? ??#}? ??? ??#?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;? ?#?}? ?#}? ? }
結果如圖:
iis站點
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END