Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2768645
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: LINUX

2011-12-29 22:06:45

学习过程记录如下:感谢为我提供帮助的朋友们!

1: 在一台机器上安装nginx(过程省略),该机器的ip为:192.168.1.2
2:在另一台机器上安装php+mysql+apache(过程省略) ,该机器的ip为:192.168.1.9
3:将nginx和apache整合起来!
nginx.conf如下:
  1. [root@qht124 conf]# cat nginx.conf
  2. user www www;
  3. worker_processes 4;

  4. # [ debug | info | notice | warn | error | crit ]
  5. error_log /usr/local/nginx/logs/nginx_error.log crit;
  6. pid /usr/local/nginx/nginx.pid;
  7. #Specifies the value for maximum file descriptors that can be opened by this process.
  8. worker_rlimit_nofile 51200;
  9. events
  10. {
  11. use epoll;
  12. worker_connections 51200;
  13. }

  14. http
  15. {
  16. include mime.types;
  17. default_type application/octet-stream;
  18. source_charset GB2312;
  19. server_names_hash_bucket_size 256;
  20. client_header_buffer_size 256k;
  21. large_client_header_buffers 4 256k;

  22. #size limits
  23. client_max_body_size 50m;
  24. client_body_buffer_size 256k;
  25. client_header_timeout 3m;
  26. client_body_timeout 3m;
  27. send_timeout 3m;
  28. keepalive_timeout 120;
  29. tcp_nodelay on;

  30. include vhosts/upstream.conf;
  31. include vhosts/

  32. }
在nginx的安装目录下新建一个conf目录,目录里有两个文件,分别为upstream.conf和 这两个文件的内容如下:

  1. [root@qht124 conf]# pwd
  2. /usr/local/nginx/conf
  3. [root@qht124 conf]# cd vhosts/
  4. [root@qht124 vhosts]# ls
  5. upstream.conf
  6. [root@qht124 vhosts]# pwd
  7. /usr/local/nginx/conf/vhosts
  8. [root@qht124 vhosts]# cat upstream.conf
  9. upstream {
  10. server 192.168.1.9:80;
  11. }
  12. [root@qht124 vhosts]# cat
  13. server
  14. {
  15. listen 80;
  16. server_name ;
  17. charset GB2312;
  18. index index.php index.html index.htm;
  19. root /usr/vhome/d/e/f/def.com/www;

  20. location ~ ^/NginxStatus/ {
  21. stub_status on;
  22. access_log off;
  23. }

  24. location / {
  25. proxy_redirect off ;
  26. proxy_set_header Host $host;
  27. proxy_set_header X-Real-IP $remote_addr;
  28. proxy_set_header REMOTE-HOST $remote_addr;
  29. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  30. client_max_body_size 50m;
  31. client_body_buffer_size 256k;
  32. proxy_connect_timeout 30;
  33. proxy_send_timeout 30;
  34. proxy_read_timeout 60;
  35. proxy_buffer_size 256k;
  36. proxy_buffers 4 256k;
  37. proxy_busy_buffers_size 256k;
  38. proxy_temp_file_write_size 256k;
  39. proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
  40. proxy_max_temp_file_size 128m;
  41. proxy_pass http://;
  42. }

  43. #location ~* \.(jpg|jpeg|gif|png|swf|html)$ {
  44. #if (-f $request_filename) {
  45. #root /usr/vhome/d/e/f/def.com/www;
  46. #expires 1d;
  47. #break;
  48. #} ##将这一段注释掉,则所有的访问都叫给apache去处理!否则静态文件会去执行192.168.1.2下的/usr/vhome/d/e/f/def.com/www下的内容。我在192.168.1.9的/usr/vhome/d/e/f/def.com/www下方一个index.php,在192,168.1.2的/usr/vhome/d/e/f/def.com/www下放一个a.jpg和index.html文件,然后手动运行/index.html和/a.jpg则会执行192.168.1.2下的内容(显然是nginx处理了静态页面)
  49. #}

  50. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  51. '$status $body_bytes_sent "$http_referer" '
  52. '"$http_user_agent" $http_x_forwarded_for';
  53. access_log /exp/nginxlogs/_access.log access;

  54. }
  55. [root@qht124 vhosts]#
然后再192.168.1.9上httpd.conf中的配置如下:
在httpd.conf中的最后加入一句:
Include conf/vhost.conf

在/usr/local/apache2/conf目录下vhosts.conf文件内容如下:
  1. [root@qht2 conf]# pwd
  2. /usr/local/apache2/conf
  3. [root@qht2 conf]# cat vhost.conf
  4. NameVirtualHost *
  5. ServerName
  6. ScriptAlias /cgi-bin/ /usr/vhome/d/e/f/def.com/cgi-bin/
  7. DocumentRoot /usr/vhome/d/e/f/def.com/www
  8. DirectoryIndex index.html index.jsp index.php
  9. Order allow,deny
  10. Allow from all
  11. php_admin_value open_basedir /usr/vhome/d/e/f/def.com:/usr/vhome/tmp:/opt/tomcat/bin
最后在一台客户端上,我的是xp系统,做本地解析,在C:\WINDOWS\system32\drivers\etc下hosts文件添加记录如下:
  1. 192.168.1.2 def.com
  2. 192.168.1.2
并在1912.168.1.9上:
mkdir -p /usr/vhome/d/e/f/def.com/www
cd /usr/vhome/d/e/f/def.com/www
touch index.php
内容为:
  1. [root@qht2 www]# cat index.php
  2. phpinfo();
  3. ?>
  4. [root@qht2 www]# pwd
  5. /usr/vhome/d/e/f/def.com/www
  6. [root@qht2 www]#
 测试访问见附件:



阅读(2663) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~