VPS侦探论坛

 找回密码
 注册
查看: 10120|回复: 9

军哥进来,有个VHOST问题请教一下

[复制链接]
发表于 2010-5-25 16:35:14 | 显示全部楼层 |阅读模式

我输入./vhost.sh后 设置了域名为www.baowang.com 并且把目录放到wwwroot/www (我新建了个目录),所以现在/usr/local/nginx/conf/vhost 配置如下:

server
{
  listen       80;
  server_name www.baowang.com;
  index index.html index.htm index.php default.html default.htm default.php;
  root  .home/wwwroot/www;
  include other.conf;
  location ~ .*\.(php|php5)?$
   {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
   }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
  location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
  log_format  www.baowang.com  '$remote_addr - $remote_user [$time_local] $request '
             '$status $body_bytes_sent $http_referer '
             '$http_user_agent $http_x_forwarded_for';
  access_log  www.baowang.com.log  www.baowang.com;
}






现在有个问题, 如果我想创立子域名, 例如我想创立个 forume.baowang.com 子域名, DNS那边做好后. 我在服务器也同时创立了目录 forum, 请问我是应该修改/usr/local/nginx/conf/vhost 配置加上子域名的项目.

还是修改/usr/local/nginx/conf/nginx.conf 文件, 还是要同时这2个文件都要修改.  


请给指点, 谢谢.
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2010-5-25 16:56:21 | 显示全部楼层


重新执行 ./vhost.sh 添加 forume.baowang.com  域名 并设定目录!
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2010-5-25 17:08:46 | 显示全部楼层

楼上正解,域名添加ns之后,再到vps执行vhost.sh,添加域名,指定目录即可。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2010-5-25 17:40:58 | 显示全部楼层



谢谢楼上的.

那意思就是说/usr/local/nginx/conf/nginx.conf   这个配置文件不需要改动? 只在VHOST.CONF文件哪里修改吗??


那还有个问题, 我如果想加上REWRITE规则,应该在哪里修改?  是上述2个文件中哪个?
我看了文件觉得很奇怪, 如果按照你们思路, 子域名在VHOST中改, 但我同时发现NGINX.CONF文件有和REWRITE 等相关的, 但VHOST.CONF中没有.我基本迷惑了,请楼上给于指点.

[ 本帖最后由 spectrum 于 2010-5-25 17:45 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2010-5-25 17:53:45 | 显示全部楼层

/usr/local/nginx/conf/nginx.conf   
最下面
include  vhost   就是把 vhost 下面的所有 conf 文件都包含了

可以将 REWRITE 的相关文件写成 **.conf 放在 /usr/local/nginx/conf 中,在 vhost/域名.conf  中再次使用 include  **.conf   即可。

军哥运维代购:http://shop63846532.taobao.com/

发表于 2010-5-25 18:02:31 | 显示全部楼层

rewrite规则最好在vhost下的各个站点的conf里添加比如我有个配置文件为:/usr/local/nginx/conf/vhost/yorl.us.conf内容为:
  1. server
  2.         {
  3.                 listen       80;
  4.                 server_name yorl.us;
  5.                 index index.html index.htm index.php default.html default.htm default.php;
  6.                 root  /home/wwwroot/yorl.us;

  7.                 location ~ .*\.(php|php5)?$
  8.                         {
  9.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  10.                                 #fastcgi_pass  127.0.0.1:9000;
  11.                                 fastcgi_index index.php;
  12.                                 include fcgi.conf;
  13.                         }

  14.                 if (!-d $request_filename){
  15.                         set $rule_0 1$rule_0;
  16.                 }
  17.                 if (!-f $request_filename){
  18.                         set $rule_0 2$rule_0;
  19.                 }
  20.                 if ($rule_0 = "21"){
  21.                         rewrite /. /./index.php last;
  22.                 }


  23.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  24.                         {
  25.                                 expires      30d;
  26.                         }

  27.                 location ~ .*\.(js|css)?$
  28.                         {
  29.                                 expires      12h;
  30.                         }

  31.                 access_log   off;
  32.         }
  33. server
  34.         {
  35.                 listen       80;
  36.                 server_name www.yorl.us;
  37.                 index index.html index.htm index.php default.html default.htm default.php;
  38.                 root  /home/wwwroot/yorl.us;

  39.                 location ~ .*\.(php|php5)?$
  40.                         {
  41.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  42.                                 #fastcgi_pass  127.0.0.1:9000;
  43.                                 fastcgi_index index.php;
  44.                                 include fcgi.conf;
  45.                         }

  46.                 if (!-d $request_filename){
  47.                         set $rule_0 1$rule_0;
  48.                 }
  49.                 if (!-f $request_filename){
  50.                         set $rule_0 2$rule_0;
  51.                 }
  52.                 if ($rule_0 = "21"){
  53.                         rewrite /. /./index.php last;
  54.                 }


  55.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  56.                         {
  57.                                 expires      30d;
  58.                         }

  59.                 location ~ .*\.(js|css)?$
  60.                         {
  61.                                 expires      12h;
  62.                         }

  63.                 access_log   off;
  64.         }
  65. server
  66.         {
  67.                 listen       80;
  68.                 server_name img.yorl.us pic.yorl.us;
  69.                 index index.html index.htm index.php default.html default.htm default.php;
  70.                 root  /home/wwwroot/yopic.us;

  71.                 location ~ .*\.(php|php5)?$
  72.                         {
  73.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  74.                                 #fastcgi_pass  127.0.0.1:9000;
  75.                                 fastcgi_index index.php;
  76.                                 include fcgi.conf;
  77.                         }


  78.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  79.                         {
  80.                                 expires      30d;
  81.                         }

  82.                 location ~ .*\.(js|css)?$
  83.                         {
  84.                                 expires      12h;
  85.                         }

  86.                 access_log   off;
  87.         }
  88. server
  89.         {
  90.                 listen       80;
  91.                 server_name pwd.yorl.us;
  92.                 index index.html index.htm index.php default.html default.htm default.php;
  93.                 root  /home/wwwroot/yorl.us/pwd;

  94.                 location ~ .*\.(php|php5)?$
  95.                         {
  96.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  97.                                 #fastcgi_pass  127.0.0.1:9000;
  98.                                 fastcgi_index index.php;
  99.                                 include fcgi.conf;
  100.                         }


  101.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  102.                         {
  103.                                 expires      30d;
  104.                         }

  105.                 location ~ .*\.(js|css)?$
  106.                         {
  107.                                 expires      12h;
  108.                         }

  109.                 access_log   off;
  110.         }
复制代码
其中包含了几个字域名的配置,以及简单的rewrite规则
  1.                 if (!-d $request_filename){
  2.                         set $rule_0 1$rule_0;
  3.                 }
  4.                 if (!-f $request_filename){
  5.                         set $rule_0 2$rule_0;
  6.                 }
  7.                 if ($rule_0 = "21"){
  8.                         rewrite /. /./index.php last;
  9.                 }
复制代码
rewrite规则是要写在location{}内的

哎呀好丢人,粘错内容了!

[ 本帖最后由 shazhumaiyou 于 2010-5-25 18:08 编辑 ]
发表于 2010-5-25 18:07:10 | 显示全部楼层

不一样吗??



server
        {
                listen       80;
                server_name  ;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/1111111;
                include other.conf;
                location ~ .*\.(php|php5)?$
                        {
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fcgi.conf;
                        }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2010-5-25 22:22:57 | 显示全部楼层

谢谢上面2位, 为了简单起见, 我选择用VHOST.CONF文件来做子域名和REWRITE文件.  我是否可以删除NGINX.CONF 这个文件,意思是不想麻烦,我只配置VHOST,因为按照2位思路,VHOST是起主要作用的, 请问我的思路正确吗??

或者按照2位思路,我配置VHOST.CONF这个文件就可以了, NGINX.CONF这个文件其实是可以不理睬的,因为在LNMP思路中VHOST去掉了NGINX.CONF作用, 我对吗?


急切等待回答.

[ 本帖最后由 spectrum 于 2010-5-25 22:28 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2010-5-25 22:47:37 | 显示全部楼层

回复 8# 的帖子



直接用./vhost.sh 添加就可以
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2010-5-25 23:51:11 | 显示全部楼层



谢谢军哥,我可以直接把NGINX.CONF 文件内容复制到VHOST.CONF中后, 以后就在VHOST.CONF中修改吧( 目前我发现VHOST.CONF 和NINGX.CONF初始化内容不一样,明显的NGINX.CONF的要丰富些),这是第一个问题.代码如下


  1. 以下为VHOST.CONF

  2. server
  3. {
  4. listen 80;
  5. server_name www.baowang.com;
  6. index index.html index.htm index.php default.html default.htm default.php;
  7. root .home/wwwroot/www;

  8. include other.conf;
  9. location ~ .*\.(php|php5)?$
  10. {
  11. fastcgi_pass unix:/tmp/php-cgi.sock;
  12. fastcgi_index index.php;
  13. include fcgi.conf;
  14. }

  15. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  16. {
  17. expires 30d;
  18. }

  19. location ~ .*\.(js|css)?$
  20. {
  21. expires 12h;
  22. }

  23. log_format www.baowang.com '$remote_addr - $remote_user [$time_local] $request '
  24. '$status $body_bytes_sent $http_referer '
  25. '$http_user_agent $http_x_forwarded_for';
  26. access_log www.baowang.com.log www.baowang.com;
  27. }
复制代码
  1. 以下为NGINX.CONF代码

  2. user www www;

  3. worker_processes 1;

  4. error_log /home/wwwroot/logs/nginx_error.log crit;

  5. pid /usr/local/nginx/logs/nginx.pid;

  6. #Specifies the value for maximum file descriptors that can be opened by this process.
  7. worker_rlimit_nofile 51200;

  8. events
  9. {
  10. use epoll;
  11. worker_connections 51200;
  12. }

  13. http
  14. {
  15. include mime.types;
  16. default_type application/octet-stream;

  17. server_names_hash_bucket_size 128;
  18. client_header_buffer_size 32k;
  19. large_client_header_buffers 4 32k;
  20. client_max_body_size 8m;

  21. sendfile on;
  22. tcp_nopush on;

  23. keepalive_timeout 60;

  24. tcp_nodelay on;

  25. fastcgi_connect_timeout 300;
  26. fastcgi_send_timeout 300;
  27. fastcgi_read_timeout 300;
  28. fastcgi_buffer_size 64k;
  29. fastcgi_buffers 4 64k;
  30. fastcgi_busy_buffers_size 128k;
  31. fastcgi_temp_file_write_size 256k;

  32. gzip on;
  33. gzip_min_length 1k;
  34. gzip_buffers 4 16k;
  35. gzip_http_version 1.0;
  36. gzip_comp_level 2;
  37. gzip_types text/plain application/x-javascript text/css application/xml;
  38. gzip_vary on;

  39. #limit_zone crawler $binary_remote_addr 10m;

  40. server
  41. {
  42. listen 80;
  43. server_name baowang.com;
  44. index index.html index.htm index.php;
  45. root /home/wwwroot/www;

  46. location ~ .*\.(php|php5)?$
  47. {
  48. fastcgi_pass unix:/tmp/php-cgi.sock;
  49. fastcgi_index index.php;
  50. include fcgi.conf;
  51. }

  52. location /status {
  53. stub_status on;
  54. access_log off;
  55. }

  56. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  57. {
  58. expires 30d;
  59. }

  60. location ~ .*\.(js|css)?$
  61. {
  62. expires 12h;
  63. }

  64. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  65. '$status $body_bytes_sent "$http_referer" '
  66. '"$http_user_agent" $http_x_forwarded_for';
  67. access_log /home/wwwroot/logs/access.log access;
  68. }
  69. include vhost/*.conf;
  70. }
复制代码
我同时参考了张宴的博客: http://blog.s135.com/nginx_php_v6/
准备下面参考张宴文章优化:

1.优化LINUX内核, 并手动创立子目录(对应子域名)在wwwroot下,记得参考张宴文章修改文件属性.

2.修改NINGX 平滑改动配置(是否LNMP已经默认配置好)

3.另外修改最大连接为128(max_children">128),因为我内存超过3G
PHP-FPM中的 Sets the limit on the number of simultaneous requests that will be served.
        Equivalent to Apache MaxClients directive.
        Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
        Used with any pm_style.
        <value name="max_children">128</value>
以上请参考张宴博客对应部分进行优化.



此外:

IAMP的模块, 避免论坛无法发邮件,请问如何解决?

如何升级NGINX到0.8.36 (可选项目,未来考虑)


等待你的回复,谢谢.

[ 本帖最后由 spectrum 于 2010-5-25 23:55 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-8 09:10 , Processed in 0.029811 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表