nginx配置相關介紹
更新時間:2013年02月09日 17:36:46 作者:
本文為大家介紹一下nginx配置的相關介紹,供大家參考
復制代碼 代碼如下:
#運行用戶
user nobody nobody;
#啟動進程
worker_processes 2;
#全局錯誤日志及PID文檔
error_log logs/error.log notice;
pid logs/Nginx.pid;
#工作模式及連接數(shù)上限
events {
use epoll;
worker_connections 1024;
}
#設定http服務器,利用他的反向代理功能提供負載均衡支持
http {
#設定mime類型
include conf/mime.types;
default_type application/octet-stream;
#設定日志格式
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';
#設定請求緩沖
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#開啟gzip模塊
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
#設定access log
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#設定負載均衡的服務器列表
upstream mysvr {
#weigth參數(shù)表示權值,權值越高被分配到的幾率越大
#本機上的Squid開啟3128端口
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
#設定虛擬主機
server {
listen 80;
server_name 192.168.8.1
chabaoo.cn
charset gb2312;
#設定本虛擬主機的訪問日志
access_log logs/chabaoo.cn.access.log main;
#假如訪問 /img/*, /js/*, /css/* 資源,則直接取本地文檔,不通過squid
#假如這些文檔較多,不推薦這種方式,因為通過squid的緩存效果更好
location ~ ^/(img|js|css)/ {
root /data3/Html;
expires 24h;
}
#對 "/" 啟用負載均衡
location / {
proxy_pass http://mysvr;
proxy_redirect off;
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_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#設定查看Nginx狀態(tài)的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
}
}
備注:conf/htpasswd 文檔的內容用 apache 提供的 htpasswd 工具來產生即可,內容大致如下:
3.) 查看 Nginx 運行狀態(tài) 輸入地址http://192.168.8.1/NginxStatus/ 。
輸入驗證帳號密碼,即可看到類似如下內容:
Active connections: 328
server accepts handled requests
9309 8982 28890
Reading: 1 Writing: 3 Waiting: 324
第一行表示現(xiàn)在活躍的連接數(shù),第三行的第三個數(shù)字表示Nginx運行到現(xiàn)在的連接數(shù)。
您可能感興趣的文章:
- Nginx配置優(yōu)化詳解
- IIS啟用GZip壓縮的詳細教程(圖文)
- IIS啟用GZIP壓縮js、css無效的原因及解決方法
- 使用php判斷服務器是否支持Gzip壓縮功能
- 設置tomcat啟用gzip壓縮的具體操作方法
- 使用php判斷網頁是否gzip壓縮
- Apache啟用GZIP壓縮網頁傳輸方法
- apache啟用gzip壓縮的實現(xiàn)方法
- php gzip壓縮輸出的實現(xiàn)方法
- php簡單開啟gzip壓縮方法(zlib.output_compression)
- 啟用IIS的GZIP壓縮功能的圖文方法
- Gzip壓縮啟用圖文方法詳細說明【IIS6.0、Apache】
- Gzip壓縮無效的終極解決方案!
- IIS開啟GZIP壓縮效率對比及部署方法小結
- win2008 IIS7中啟用JS的gzip壓縮的方法
- 在IIS上啟用Gzip壓縮詳細方法(HTTP壓縮)
- IIS啟用頁面Gzip壓縮實現(xiàn)說明
- PHP zlib擴展實現(xiàn)頁面GZIP壓縮輸出
- windows服務器上的iis Gzip壓縮功能啟用
- nginx配置gzip壓縮頁面
相關文章
解決Nginx無法啟動 -10013: An attempt was
這篇文章主要給大家介紹了解決用nginx -t 發(fā)成Nginx無法啟動報錯10013: An attempt was made to access a socket in a way forbidden by its access permissions的問題,需要的朋友可以參考下2023-11-11nginx刷新頁面出現(xiàn)404解決方案(親測有效)
本文主要介紹了nginx刷新頁面出現(xiàn)404解決方案,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03Nginx 解決WebApi跨域二次請求以及Vue單頁面的問題
下面小編就為大家分享一篇Nginx 解決WebApi跨域二次請求以及Vue單頁面的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01基于Nginx實現(xiàn)一個灰度上線系統(tǒng)的示例代碼
本文主要介紹了基于Nginx實現(xiàn)一個灰度上線系統(tǒng)的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-07-07Nginx中使用gzip_http_version解決CDN只支持http 1.0問題
這篇文章主要介紹了Nginx中使用gzip_http_version解決CDN只支持http 1.0問題,問題原因是在Header信息中看到Transfer-Encoding: chunked,使用本文方法就可以解決這個問題,需要的朋友可以參考下2014-09-09