博文

目前显示的是标签为“Nginx”的博文

nginx查看并发连接数

图片
通过查看Nginx的并发连接,我们可以更清除的知道网站的负载情况。Nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过 web界面,一种是通过命令,web查看要比命令查看显示的结果精确一些。 通过web界面查看时Nginx需要开启status模块,也就是安装Nginx时加上 –with-http_stub_status_module 然后配置Nginx.conf,在server点里面加入如下内容 location /status { stub_status on; access_log /usr/local/nginx/logs/status.log; auth_basic “NginxStatus”; } 配置完后重新启动Nginx后我们可以通过浏览器访问http://localhost/status 查看 解析: Active connections //当前 Nginx 正处理的活动连接数。 server accepts handled requests //总共处理了8 个连接 , 成功创建 8 次握手,总共处理了500个请求。 Reading //nginx 读取到客户端的 Header 信息数。 Writing //nginx 返回给客户端的 Header 信息数。 Waiting //开启 keep-alive 的情况下,这个值等于 active – (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接

解决nginx出现File not found的问题

使用php-fpm解析PHP,”No input file specified”,”File not found”是令nginx新手头疼的常见错误,原因是php-fpm进程找不到SCRIPT_FILENAME配置的要执行的.php文件,php-fpm返回给nginx的默认404错误提示。 比如我的网站doucument_root下没有test.php,访问这个文件时通过抓包可以看到返回的内容。   HTTP/1.1 404 Not Found Date: Fri, 21 Dec 2012 08:15:28 GMT Content-Type: text/html Proxy-Connection: close Server: nginx/1.2.5 X-Powered-By: PHP/5.4.7 Via: 1.1 c3300 (NetCache NetApp/6.0.7) Content-Length: 16   File not found.   很多人不想用户直接看到这个默认的404错误信息,想自定义404错误. 给出解决办法前我们来先分析下如何避免出现这类404错误,然后再说真的遇到这种情况(比如用户输入一个错误不存在的路径)时该怎么办,才能显示自定义的404错误页。 一、错误的路径被发送到php-fpm进程 出现这类错误,十个有九个是后端fastcgi进程收到错误路径(SCRIPT_FILENAME),而后端fastcgi收到错误路径的原因大都是配置错误。   常见的nginx.conf的配置如下: server { listen [::]:80; server_name example.com www.example.com; access_log /var/www/logs/example.com.access.log;   location / { root /var/www/example.com; index index.html index.htm index.pl; }   location /images { autoindex on; }   location ~ \.php$ { fastcgi_pass 127.0.0.1:...

Nginx配置文件nginx.conf中文详解

#定义Nginx运行的用户和用户组 user www www;   #nginx进程数,建议设置为等于CPU总核心数。 worker_processes 8;   #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ] error_log /var/log/nginx/error.log info;   #进程文件 pid /var/run/nginx.pid;   #一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。 worker_rlimit_nofile 65535;   #工作模式与连接数上限 events { #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。 use epoll; #单个进程最大连接数(最大连接数=连接数*进程数) worker_connections 65535; }   #设定http服务器 http { include mime.types; #文件扩展名与文件类型映射表 default_type application/octet-stream; #默认文件类型 #charset utf-8; #默认编码 server_names_hash_bucket_size 128; #服务器名字的hash表大小 client_header_buffer_size 32k; #上传文件大小限制 large_client_header_buffers 4 64k; #设定请求缓 client_max_body_size 8m; #设定请求缓 sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度...

nginx中配置ip直接访问的默认站点

nginx中,每个站点都是由一个server段定义的,这里面设定了监听的ip和端口,站点的域名,根目录等信息。但一般来说vps主机上每个ip上会对应几个不同的站点。这样就会出现一个问题,直接访问这个ip的话,访问的会是哪个站点? 答案是这样的:在Listen ip:port; 这个指令行中,有一个参数default_server,指定了它后,这个server段就会是这个ip的默认站点;如果没有这个参数,那么默认ip直接访问的是nginx.conf中出现的第一个server段对应的站点。 server{ listen 80 default_server; server_name ixq.us; rewrite ^ http://www.ixq.us$request_uri?; }

Freebsd8.2 32位ports安装php5.2+fpm+mysql5.1+nginx+Zend

一、安装软件前的准备: 系统的安装:让机房最小化安装32位freebsd8.2系统。 ports的安装:机房装好系统后,远程登录,自己在线安装ports 命令: sysinstall->Configure->Distributions->ports->FTP->China->OK 修改系统密码:passwd回车 二、手动安装nginx+php (1) 进入系统后,准备cvs更新: 1. cd /usr/ports/net/cvsup-without-gui # make install clean 2. cp /usr/share/examples/cvsup/ports-supfile /etc/ports-supfile 3. # ee /etc/ports-supfile 将其中的#*default host=CHANGE_THIS.FreeBSD.org一行改为: *default host=cvsup4.FreeBSDchina.org {也可以指定更新版本日期,例如加上:*default date=2009.10.05.00.00.00 (这个可以省略) } 4. 更新ports /usr/local/bin/cvsup -g -L 2 /etc/ports-supfile 2) 安装mysql #cd /usr/ports/databases/mysql51-server #make WITH_CHARSET=gbk WITH_XCHARSET=all WITH_PROC_SCOPE_PTH=yes BUILD_OPTIMIZED=yes BUILD_STATIC=yes SKIP_DNS_CHECK=yes WITHOUT_INNODB=yes install clean #cp /usr/local/share/mysql/my-large.cnf /usr/local/etc/my.cnf ##mysql的优化参数,也可以手动修改 #rehash # mysql_install_db –user=mysql ##初始化mysql #/usr/local/bin/mysqld_safe & ##启动mysql #/usr/local/bin/mysqladmin -u root password...

启用gzip模块优化网页

Nginx   http { : include conf/mime.types; : gzip on; : gzip_min_length 1000; : gzip_buffers 4 8k; : gzip_http_version 1.1; : gzip_types text/plain application/x-javascript text/css text/html application/xml; } 重启nginx IIS6 打开Internet信息服务(IIS)管理器,右击”网站”→“属性”,选择”服务”。在”HTTP压缩”框中选中”压缩应用程序文件”和”压缩静态文件”,按需要设置”临时目录”和”临时目录的最大限制”; 在Internet信息服务(IIS)管理器,右击”Web服务扩展”→“增加一个新的Web服务扩展…“,在”新建Web服务扩展”框中输入扩展 名”HTTPCompression”,添加”要求的文件”为C:\WINDOWS\system32\inetsrv\gzip.dll,其中 Windows系统目录根据您的安装可能有所不同,选中”设置扩展状态为允许”; 使用文本编辑器打开C:\Windows\System32\inetsrv\MetaBase.xml(建议先备份),找到Location =”/LM/W3SVC/Filters/Compression/gzip”,如果需要压缩动态文件,则将 HcDoDynamicCompression设置为”TRUE”,并在HcScriptFileExtensions中增加您要压缩的动态文件后缀名, 如aspx;如果需要压缩静态文件,则将HcDoStaticCompression和HcDoOnDemandCompression设置 为”TRUE”,并在HcFileExtensions中增加您需要压缩的静态文件后缀名,如xml、css 等;HcDynamicCompressionLevel和HcOnDemandCompLevel表示需要的压缩率,数字越小压缩率越低; 编辑完毕后保存MetaBase.xml文件;如果文件无法保存,则可能IIS正在使用该文件。打开”开始”→“管理工具”→“服务”,停止”IIS Admin Service”后,即可保存; 最后,重新启动IIS。 Apache 编辑ht...

504 Gateway Time-out(nginx)的处理

在nginx.conf配置里加入: fastcgi_buffers 8 128k; send_timeout 60; 注意添加位置在 http{ } 里,否则不工作 如下上面的设置后还是有504 Gateway Time-out错误,则继续修改添加以下部分 http{ ……………… fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; ……………… }

nginx wolf 支持伪静态文件.htaccess

if (!-e $request_filename) { rewrite ^/admin(.+)$ /admin/index.php?$1 last; rewrite ^/(.+)$ /index.php?WOLFPAGE=$1 last; }

nginx 禁止ip访问及未绑定的域名跳转

ngixn 禁止ip访问和未绑定ip的访问   server { listen 80 default; server_name _; return 500; }       nginx 将未绑定的域名跳转   server { listen 80 default; rewrite ^(.*) http://www.kogoogle.com permanent; }

Freebsd9.0安装Nginx+PHP-FPM+MySQL+eAccelerator+Memcached+phpMyAdmin

图片
更新 ports 第一种方式: portsnap (自带) 首先修改/etc/portsnap.conf SERVERNAME=portsnap.cn.freebsd.org 1.下载压缩的 Ports 套件快照到 /var/db/portsnap # portsnap fetch 2.假如是首次运行 Portsnap, 则需要将快照释放到 /usr/ports: # portsnap extract 如果您已经有装好的 /usr/ports 而只想更新, 则应执行下面的命令: # portsnap update 完成后需要退出终端重新登陆。 复制cvsup更新配置文件 # cp /usr/share/examples/cvsup/ports-supfile /etc/supfile 下面是我使用的配置,屏蔽了desktop等一些服务器用不到的软件包,源已经改成中国镜像,速度比国外的主服务器要快很多 # $FreeBSD: release/9.0.0/share/examples/cvsup/ports-supfile 219858 2011-03-22 04:31:35Z glebius $ # # This file contains all of the “CVSup collections” that make up the # FreeBSD-current ports collection. # # CVSup (CVS Update Protocol) allows you to download the latest CVS # tree (or any branch of development therefrom) to your system easily # and efficiently (far more so than with sup, which CVSup is aimed # at replacing). If you’re running CVSup interactively, and are # currently using an X display server, you should run CVSup as follows # to keep your CVS tree up-to-date: # # cvsup ...