nginx rewrite 伪静态配置参数和使用例子

nginx rewrite 伪静态配置参数和使用例子

正则表达式匹配,其中: * ~ 为区分大小写匹配 * ~* 为不区分大小写匹配 * !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配,其中: * -f和!-f用来判断是否存在文件 * -d和!-d用来判断是否存在目录 * -e和!-e用来判断是否存在文件或目录 * -x和!-x用来判断文件是否可执行 flag标记有: * last 相当于Apache里的[L]标记,表示完成r ···
Windows下Nginx + PHP5 的安装与配置方法

Windows下Nginx + PHP5 的安装与配置方法

安装 PHP5 首先,从 http://www.php.net/downloads.php 下载最新的 PHP 5.3 Windows 版本,解压至 C:php5,把压缩包中的 php.ini-recommended,更名为 php.ini,然后打开修改几个选项: 代码如下: error_reporting = E_ALL display_errors = On extension_dir = " ···
ubuntu上配置Nginx+PHP5 FastCGI服务器配置

ubuntu上配置Nginx+PHP5 FastCGI服务器配置

首先安装或编译Nginx。安装Nginx源码包可以在官方主页上下载。Ubuntu 9.04可以直接通过apt安装,也可以从这里下载最新的deb包:sudo apt-get install nginx 如果要自己编译的话,需要确保自己已经有编译器和PCRE的库(用于Nginx的rewrite模块,如果不需要这个模块可以在configure时使用./configure Cwithout-rewrite)。编译方法如下:wget tar zxvf nginx-0.5.34.tar.gzcd nginx-0.5.34./configure #默认配置安装路径为/usr/local/nginx 可以追加--prefix=/usr设置到/usrmake && make install  # install要求有root权限
nginx下的代理服务器80端口被封的解决方案

nginx下的代理服务器80端口被封的解决方案

方法如下: 首先得准备一台VPS,俺用的是国外的,,早上我已经将环境搞定了,于是迫不及待的测试了下……???啥?你吖环境都不知道配置??没关系.看哥的教程,用SSH连接上终端,挨个执行这篇文章里面的内容吧,好了.这下会了吧.其他的….命令那些的看看,也就差不多了…..好了.这些都了解的差不多了吧… 然后,我们不是80被封了嘛.咱们给网站个81端口,我说的是IIS,那啥的nginx和apache我还 ···
centos系统下LNMP环境一键安装

centos系统下LNMP环境一键安装

首先,咱们用SSH登陆到操作系统中… 然后下载安装包 代码如下:wget http://catlnmp.googlecode.com/files/lnmp1.1.zip 然后我们解压 代码如下:unzip lnmp1.1.zip 有些没有unzip的,我们这样 代码如下:yum install unzip 然后我们跳转到该目录 代码如下:cd lnmp 然后我们给文件添加权限: 代码如下:chmod +x install.sh apc.sh eaccelerator.sh 最后我们执行 代码如下:./install.sh 安装后默认的mysql用户名和密码都是root,咱们可以使用下面这个命令修改密码: 代码如下:/usr/local/mysql/bin/mysqladmin -u root -p password 你的密码 这样你就可以上传你的网站了. 程序安装路径: MySQL : /usr/local/mysql PHP : /usr/local/php Nginx : /usr/local/nginx PHPMyAdmin /home/www/phpmyadmin Web目录 /home/www FTP根目录 /home/www 注意:MYSQL数据库用户名root密码root,登陆后进入mysql数据库,找到user表,删除除了有root密码外的所有用户。 需要安装vsftp的可以执行以下命令: 代码如下:yum -y install vsftpd /etc/init.d/vsftpd start chkconfig --level 345 vsftpd on 以www用户登录的可以修改www用户密码:  代码如下:passwd www 需要安装eaccelerator的可以执行以下命令: 代码如下:./eaccelerator.sh 需要安装apc的可以执行以下命令: 代码如下:./apc.sh 注意:Eaccelerator apc 只能x癜惭b一 关于添加站点以及重启nginx等操作请参见:
高性能WEB开发 nginx HTTP服务器篇

高性能WEB开发 nginx HTTP服务器篇

第一篇:HTTP服务器 因tomcat处理静态资源的速度比较慢,所以首先想到的就是把所有静态资源(JS,CSS,image,swf) 提到单独的服务器,用更加快速的HTTP服务器,这里选择了nginx了,nginx相比apache,更加轻量级, 配置更加简单,而且nginx不仅仅是高性能的HTTP服务器,还是高性能的反向代理服务器。 目前很多大型网站都使用了nginx,新浪、网易、QQ等都使用了nginx,说明nginx的稳定性和性能还是非常不错的。 1. nginx 安装(linux) http://nginx.org/en/download.html 下载最新稳定版本 根据自己需要的功能先下载对应模板,这里下载了下面几个模块: openssl-0.9.8l,zlib-1.2.3,pcre-8.00 编译安装nginx: ./configure --without-http_rewrite_module --with-http_ssl_module --with-openssl=../../lib/openssl-0.9.8l --with-zlib=../../lib/zlib-1.2.3 --with-pcre=../../lib/pcre-8.00 --prefix=/usr/local/nginx make make install 2、nginx处理静态资源的配置 #启动GZIP压缩CSS和JS gzip on; # 压缩级别 1-9,默认是1,级别越高压缩率越大,当然压缩时间也就越长 gzip_comp_level 4; # 压缩类型 gzip_types text/css application/x-javascript; # 定义静态资源访问的服务,对应的域名:res.abc.com server { listen 80; server_name res.abc.com; # 开启服务器读取文件的缓存, open_file_cache max=200 inactive=2h; open_file_cache_valid 3h; open_file_cache_errors off; charset utf-8; # 判断如果是图片或swf,客户端缓存5天 location ~* ^.+.(ico|gif|bmp|jpg|jpeg|png|swf)$ { root /usr/local/resource/; access_log off; index index.html index.htm; expires 5d; } # 因JS,CSS改动比较频繁,客户端缓存8小时 location ~* ^.+.(js|css)$ { root /usr/local/resource/; access_log off; index index.html index.htm; expires 8h; } # 其他静态资源 location / { root /usr/local/resource; access_log off; expires 8h; } } 3、nginx 反向代理设置 # 反向代理服务,绑定域名www.abc.com server { listen 80; server_name www.abc.com; charset utf-8; # BBS使用Discuz! # 因反向代理为了提高性能,一部分http头部信息不会转发给后台的服务器, # 使用proxy_pass_header 和 proxy_set_header 把有需要的http头部信息转发给后台服务器 location ^~ /bbs/ { root html; access_log off; index index.php; # 转发host的信息,如果不设置host,在后台使用request.getServerName()取到的域名不是www.abc.com,而是127.0.0.1 proxy_set_header Host $host; # 因Discuz! 为了安全,需要获取客户端User-Agent来判断每次POST数据是否跟第一次请求来自同1个浏览器, # 如果不转发User-Agent,Discuz! 提交数据就会报"您的请求来路不正确,无法提交"的错误 proxy_pass_header User-Agent; proxy_pass http://127.0.0.1:8081; } # 其他请求转发给tomcat location / { root html; access_log off; index index.jsp; proxy_pass http://127.0.0.1:8080; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } nginx详细配置参考:http://wiki.nginx.org/ 转载请注明出处:http://www.blogjava.net/BearRui/
Nginx + php 搭建 超性能 WEB 服务器

Nginx + php 搭建 超性能 WEB 服务器

Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。 在高并发连接的情况下,Nginx是Apache服务器不错的替代品。Nginx同时也可以作为7层负载均衡服务器来使用。根据我的测试结果,Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 可以承受3万以上的 ···
一句简单命令重启nginx

一句简单命令重启nginx

但研究了一下nginx帮助后发现,有-s参数可对nginx服务进行管理: # /usr/local/nginx/sbin/nginx -h nginx version: nginx/0.7.63 Usage: nginx [-?hvVt] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help ···
封80端口应对策略 Nginx反向代理For WIN2003超级傻瓜式配置

封80端口应对策略 Nginx反向代理For WIN2003超级傻瓜式配置

Win下最新版本儿:nginx-0.8.31下载地址:下载后解压到任意位置,然后修改里面的nginx.conf和添加proxy.conf后启动Nginx.exe即可!proxy.conf内容: 代码如下: proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; # client_body_temp_path /var/nginx/client_body_temp; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; #proxy_send_lowat 12000; proxy_buffer_size 32k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; # proxy_temp_path /var/nginx/proxy_temp; proxy_ignore_client_abort on; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; proxy_max_temp_file_size 128m; nginx.conf内容: 代码如下: #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; include proxy.conf; default_type application/octet-stream; #log_format main ‘$remote_addr C $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; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} # 其他的都不用管,只要放对地方就可以,最主要是下面这一行,照着填就可以了!一行一个站,一个站对一个端口,端口不要重复,否则你的IIS内的站启动不了! server { listen 80; server_name 1.jb51.net; location / { proxy_pass http://208.28.188.249:81; }} server { listen 80; server_name 2.jb51.net; location / { proxy_pass http://208.28.188.249:82; }} } 这是代理服务器上的配置,就是找个没封80的IP或租个国外的VPS都可以,否则会和你本机已经开放的80冲突,然后通过这个代理服务器跳转到你封80的机器上,封80的机器的站点上添加个空主机头端口是81即可,这里的81是随便填的,计算机内有655535个端口你可以随便设置,这样封80就在也没什么用了! 哥再写个具体傻瓜式操作步骤: 1、上面的软件下载解压到你的80没封的服务器配置好,这上面最好不要有网站,否则会和你原来的网站用的80冲突; 2、把你的域名解析到上面没封80的IP上,然后去你封80的机器上把原来的站点上添加个空主机头端口是81,如http://192.168.0.11:81可以访问到你的网站上就可以了; 3、Nginx.exe每改一次配置文件需要在任务管理器内结束任务后再启动一次才会生效,是实时生效的!记住两个Nginx.exe的进程都要结束掉,否则没用; 4、1.jb51.net这里是换成你的域名的,多个域名用空格分开,没有限制,一个站一行,不要多个站放在一行; 5、启Nginx.exe直接双击即可,会一闪而过,只要任务管理器的进程里出现两个Nginx.exe就是正常运行了,否则就是配置文件错误没有启动; 6、出现504 Gateway Time-out这个错误是你的代理服务器无法访问http://192.168.0.11:81这个地址,你可以试下,如果你可以服务器不可以可能和你的防火墙或策略有关;
Nginx 简单的负载均衡配置示例

Nginx 简单的负载均衡配置示例

用户访问http://www.net-hb.com.cn,将其负载均衡到192.168.1.2:80、192.168.1.3:80、192.168.1.4:80、192.168.1.5:80四台服务器。   用户访问//www.jb51.net,将其负载均衡到192.168.1.7服务器的8080、8081、8082端口。   以下为配置文件nginx.conf:   引用   [table=95 ···
Nginx0.5.33+PHP5.2.5(FastCGI)搭建胜过Apache10倍的Web服务器

Nginx0.5.33+PHP5.2.5(FastCGI)搭建胜过Apache10倍的Web服务器

修正了PHP iconv和gd库冲突的BUG,增加了PHP mcrypt、memcache扩展,修改了PHP和Nginx编译参数,优化了Nginx配置文件,添加了部分功能。 Nginx ("engine x") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAPPOP3SMTP 代理服务器。 Nginx 是由 Igo Sysoev 为俄罗斯访问量第二的 ambe. 站点开发的,它已经在 ···
解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

解决Nginx + PHP(FastCGI)遇到的502 Bad Gateway错误

我让按照以下两个步骤去解决,最后在第2步中将FastCGI的timeout时间增加为300,问题解决:   PS:比较羡慕迅雷的Web服务器,16G内存。   1、查看当前的PHP FastCGI进程数是否够用: netstat -anpo | grep "php-cgi" | wc -l   如果实际使用的“FastCGI进程数”接近预设的“FastCGI进程数”,那么,说明“FastCGI进程 ···
Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)

Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)

系统环境:RHEL5 [ 2.6.18-8.el5xen ] 软件环境: nginx-0.7.17 lighttpd-1.4.20.tar.gz pcre-6.6-1.1 pcre-devel-6.6-1.1 php-5.1.6-5.el5 参考下载地址: http://sysoev.ru/nginx/nginx-0.7.17.tar.gz (最新稳定版为0.6.32) http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz ########################################################################## 一、安装支持软件 1、安装lighttpd以提取spawn-fcgi (如果站点不包含php页面,可以不安装spaw-fcgi、PHP) shell> tar zxvf lighttpd-1.4.20.tar.gz shell> cd lighttpd-1.4.20/ shell> ./configure && make shell> cp -p src/spawn-fcgi /usr/sbin/spawn-fcgi 2、安装pcre和php(以下软件) 可使用RHEL5自带的rpm包安装,过程略。 二、安装nginx shell> tar zxvf nginx-0.7.17.tar.gz shell> cd nginx-0.7.17/ shell> ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module shell> make && make install shell> ln -sf /opt/nginx/sbin/nginx /usr/sbin/ 三、nginx运行控制 1、检查配置文件有无语法错误 shell> nginx -t 2、启动(不带任何参数直接运行即可) shell> nginx 3、重新加载nginx配置 shell> killall -s HUP nginx #//或者 killall -1 nginx 4、处理完当前请求后退出nginx shell> killall -s QUIT nginx #//或者 killall -3 nginx 四、nginx配置用例 1、常规配置 shell> vi /opt/nginx/conf/nginx.conf worker_processes 1; #//工作进程数 events { use epoll; #//增加该事件提高I/O性能 work_connections 4096; } http { include mime.types; default_types application/octet-stream; sendfile on; tcp_nodelay on keepalive_timeout 60; server { listen 80; #//设置监听端口,注意不要和Apache等其他Web程序冲突 server_name www.linux.org; #//指定使用的主机名 charset utf-8; #//指定站点文件的默认编码 location / { root html; #//设置网站根目录 index index.html index.html; } error_page 500 502 503 504 /50x.html location = /50x.html { root html; } } } 2、添加状态监控 shell> vi /opt/nginx/conf/nginx.conf #//增加以下内容 location ~ ^/NginxStatus/ { stub_status on; access_log off; } shell> killall -1 nginx #//使用浏览器访问 http://nginx_server_ip/NginxStatus/ 即可看到状态统计页面。(三个数字分别表示:总共处理连接数、成功创建的握手次数、总共处理的请求数) 3、通过FastCGI方式支持PHP语言 1)启动FastCGI服务(用php-cgi做实际处理php页面的程序,用spawn-fcgi是便于同时开启多个php-cgi进程――“-C”选项控制子进程数) shell>/usr/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi -C 10 2)修改/opt/nginx/conf/nginx.conf配置文件,添加以下内容: location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } 3)重新加载配置 shell> killall -1 nginx 4、虚拟主机设置 修改nginx.conf文件,增加一个server {……}配置即可,每个虚拟主机的参数可以独立配置。 http { server { listen 80; server_name www.vhost1.com; access_log logs/vhost1.access.log main; location / { index index.html; root /var/www/vhost1; #//第1个虚拟主机的网页根目录 } } server { listen 80; server_name www.vhost2.com; access_log logs/vhost2.access.log main; location / { index index.html; root /var/www/vhost2; #//第2个虚拟主机的网页根目录 } } } 5、基于反向代理的负载均衡 修改nginx.conf文件,增加upstream配置,指定对应服务器群的IP和权重,并调整server段中的网页根目录配置。使访问nginx服务器的HTTP请求分散到Web群集中的服务器来处理。 http { upstream my_web_cluster { server 192.168.2.11:8000 weight=3; server 192.168.2.12:8000 weight=3; server 192.168.2.13:8000 weight=3; server 192.168.2.14:8000 weight=3; server 192.168.2.15:8000 weight=3; } server { listen 80; server_name www.domain.com; location / { proxy_pass http://my_web_cluster; proxy_set_header x-real-IP $remote_addr; } #//注:其他的location配置段(如关于.php文件的)需注释掉,否则可能影响该类文件的重定向。 } }
nginx 伪静态化rewrite规则

nginx 伪静态化rewrite规则

代码如下: location / { ###以下为PHPCMS 伪静态化rewrite规则 rewrite ^(.*)show-([0-9]+)-([0-9]+).html$ $1/show.php?itemid=$2&page=$3; rewrite ^(.*)list-([0-9]+)-([0-9]+).html$ $1/list.php?catid=$2&page=$3; rewrite ^ ···