Posts Tagged ‘Nginx’

Nginx 0.8 Stable Source Installation document collection


29 9月
Eureka~ Nginx has published the stable version of 0.8. Since the auto update method of ubuntu is not available so soon I decided to install it via source. Download from here: http://nginx.org/en/download.html Everything introduced official about how to install it could be found here: http://wiki.nginx.org/Install#Stable And how to configure it could be found here: http://wiki.nginx.org/Configuration When you are going to compile the source you may want to read this first: http://wiki.nginx.org/NginxInstallOptions (Notice that if you are using a ubuntu or debian server like me, you should install libssl-dev first to enable the ssl module and PCRE for the rewrite mod,which may need to be pointed the PCRE lib path manually if you have installed but not discovered by the compile program.) Then you shall have a look at: http://wiki.nginx.org/Nginx-init-ubuntu It gives you an idea how to make the /etc/init.d/nginx file to start or stop your nginx server. You may have to change the Consts part of the file especially for the DAEMON and PID variable configuring well to make sure your nginx could be start and stop functionally. Oh, and if you want to compile other 3rd part module, you will find them here: http://wiki.nginx.org/Nginx3rdPartyModules Well, here's the EOF then. Have a nice trip with your new powerful Nginx server. LOL

Nginx + PHP FastCGI on Ubuntu 傻瓜式 安装 配置 指南


17 9月
最近在公司都用的ubuntu,升级到10.0.4后发现PHP自动就到5.3了,但是某些杯具项目只能在5.2上面跑,于是折腾了很久,最后选择删光原有的环境装了Zend Server... 好吧,那是另外一个故事了。 大家知道我是个“最新版本控”,所以5.3还是要玩的,于是想到了Nginx这东东一直想弄还没机会搞,于是有了这篇傻瓜式记录。之前也看了张宴之类的大师怎么装这个环境,不过貌似超复杂,像我这在linux水平很初级的同学基本看完就晕了。 于是google了一下,嘿,还真找到了一些英文的资料,于是挑重点的翻译在此,以备不时之需。废话至此,以下正文: 我首先装的是nginx,很容易,一句话: aptitude install nginx 然后FastCgi: aptitude install php5-cgi 恭喜,如果没有报错的话,一切就完成大半了。超傻瓜吧。。。 实验一下: php-cgi -b 127.0.0.1:9000 有报错的话自己处理,反正我没出问题。 好,下面是关键部分,怎么让这东西自动启动。反正作为新手的我对这种感觉还是很神奇的。 vi /etc/init.d/php-fastcgi 把下面这些复制过去:
  1. #!/bin/bash
  2. BIND=127.0.0.1:9000
  3. USER=www-data
  4. PHP_FCGI_CHILDREN=15
  5. PHP_FCGI_MAX_REQUESTS=1000
  6.  
  7. PHP_CGI=/usr/bin/php-cgi
  8. PHP_CGI_NAME=`basename $PHP_CGI`
  9. PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
  10. RETVAL=0
  11.  
  12. start() {
  13.       echo -n "Starting PHP FastCGI: "
  14.       start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
  15.       RETVAL=$?
  16.       echo "$PHP_CGI_NAME."
  17. }
  18. stop() {
  19.       echo -n "Stopping PHP FastCGI: "
  20.       killall -q -w -u $USER $PHP_CGI
  21.       RETVAL=$?
  22.       echo "$PHP_CGI_NAME."
  23. }
  24.  
  25. case "$1" in
  26.     start)
  27.       start
  28.   ;;
  29.     stop)
  30.       stop
  31.   ;;
  32.     restart)
  33.       stop
  34.       start
  35.   ;;
  36.     *)
  37.       echo "Usage: php-fastcgi {start|stop|restart}"
  38.       exit 1
  39.   ;;
  40. esac
  41. exit $RETVAL
加上执行权限: chmod +x /etc/init.d/php-fastcgi 跑跑看: /etc/init.d/php-fastcgi start 都没问题的话: update-rc.d php-fastcgi defaults 大功告成。 改nginx配置:(/etc/nginx/nginx.conf) 加上类似这样的东西:
server {
        listen          80;
        server_name     example.com;

        access_log      /var/log/nginx/example.com.access_log;
        error_log       /var/log/nginx/example.com.error_log warn;

        root            /var/www/example.com/public;

        index           index.php index.html;
        fastcgi_index   index.php;

        location ~ \.php {
                include /etc/nginx/fastcgi_params;
                keepalive_timeout 0;
                fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_pass    127.0.0.1:9000;
        }
}

ok,一切完成。

参考文章:
http://tomasz.sterna.tv/2009/04/php-fastcgi-with-nginx-on-ubuntu/
http://wiki.nginx.org/NginxHttpFcgiModule
——————————补充———————————— 有关权限,原来用apache的时候只要再httpd.conf里面改user和group就可以控制启动服务的用户和组了。 但是,用nginx+fastcgi的时候,需要改2个地方,nginx的那个都能想到,另外就是上面那段/etc/init.d/php-fastcgi脚本开头的,user也要改,我今天就忘记改了,被妖了半天,杯具。。。

Some links about squid and nginx


12 6月
Squid 官网 doc :http://www.squid-cache.org/Doc/ 反向代理概念及Squid简单实现方法: http://linux.ccidnet.com/art/737/20070417/1063859_1.html 使用反向代理后可能碰到的客户端真实IP地址获取问题: http://wangpan80.javaeye.com/blog/286702 (代码是java的大概意思看看就好) nginx异步反向代理: http://www.net527.cn/a/caozuoxitong/Linux/1514.html nginx反向代理做cache配置:http://blog.sina.com.cn/s/blog_5dc960cd0100gvk2.html(额,这篇有点乱,没仔细看) Round Robin DNS Load Balancing: http://content.websitegear.com/article/load_balance_dns.htm(with BIND name server) nginx常识扫盲:http://edu.codepub.com/2010/0516/22746.php nginx url hash模块:http://www.wurmbai.info/2010/02/nginx_url-hash/ 另外一篇同上: http://wiki.nginx.org/NginxHttpUpstreamRequestHashModule (url hash就是类似所谓的7层负载均衡,可以通过url来分配不同的业务逻辑到不同的服务器上面去,很好很强大) nginx request process:http://nginx.org/en/docs/http/request_processing.html nginx server names:http://nginx.org/en/docs/http/server_names.html nginx mogileFS module: http://grid.net.ru/nginx/mogilefs.en.html nginx和squid结合的概念:http://edu.codepub.com/2010/0202/20282.php 这些文章主要是我学习nginx做url hash负载+squid反向代理缓存查阅的一些资料,可能有所遗漏,暂时整理至此。

貓熊寶寶幼齒園

姜經緯的博客