spectrum 发表于 2010-5-25 16:35:14

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

我输入./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_passunix:/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_formatwww.baowang.com'$remote_addr - $remote_user [$time_local] $request '
             '$status $body_bytes_sent $http_referer '
             '$http_user_agent $http_x_forwarded_for';
access_logwww.baowang.com.logwww.baowang.com;
}






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

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


请给指点, 谢谢.

zhxyun 发表于 2010-5-25 16:56:21

重新执行 ./vhost.sh 添加 forume.baowang.com域名 并设定目录!:lol

shazhumaiyou 发表于 2010-5-25 17:08:46

楼上正解,域名添加ns之后,再到vps执行vhost.sh,添加域名,指定目录即可。

spectrum 发表于 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 编辑 ]

zhxyun 发表于 2010-5-25 17:53:45

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

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

shazhumaiyou 发表于 2010-5-25 18:02:31

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

                location ~ .*\.(php|php5)?$
                        {
                              fastcgi_passunix:/tmp/php-cgi.sock;
                              #fastcgi_pass127.0.0.1:9000;
                              fastcgi_index index.php;
                              include fcgi.conf;
                        }

                if (!-d $request_filename){
                        set $rule_0 1$rule_0;
                }
                if (!-f $request_filename){
                        set $rule_0 2$rule_0;
                }
                if ($rule_0 = "21"){
                        rewrite /. /./index.php last;
                }


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

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

                access_log   off;
      }
server
      {
                listen       80;
                server_name www.yorl.us;
                index index.html index.htm index.php default.html default.htm default.php;
                root/home/wwwroot/yorl.us;

                location ~ .*\.(php|php5)?$
                        {
                              fastcgi_passunix:/tmp/php-cgi.sock;
                              #fastcgi_pass127.0.0.1:9000;
                              fastcgi_index index.php;
                              include fcgi.conf;
                        }

                if (!-d $request_filename){
                        set $rule_0 1$rule_0;
                }
                if (!-f $request_filename){
                        set $rule_0 2$rule_0;
                }
                if ($rule_0 = "21"){
                        rewrite /. /./index.php last;
                }


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

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

                access_log   off;
      }
server
      {
                listen       80;
                server_name img.yorl.us pic.yorl.us;
                index index.html index.htm index.php default.html default.htm default.php;
                root/home/wwwroot/yopic.us;

                location ~ .*\.(php|php5)?$
                        {
                              fastcgi_passunix:/tmp/php-cgi.sock;
                              #fastcgi_pass127.0.0.1:9000;
                              fastcgi_index index.php;
                              include fcgi.conf;
                        }


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

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

                access_log   off;
      }
server
      {
                listen       80;
                server_name pwd.yorl.us;
                index index.html index.htm index.php default.html default.htm default.php;
                root/home/wwwroot/yorl.us/pwd;

                location ~ .*\.(php|php5)?$
                        {
                              fastcgi_passunix:/tmp/php-cgi.sock;
                              #fastcgi_pass127.0.0.1:9000;
                              fastcgi_index index.php;
                              include fcgi.conf;
                        }


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

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

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

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

[ 本帖最后由 shazhumaiyou 于 2010-5-25 18:08 编辑 ]

zhxyun 发表于 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_passunix:/tmp/php-cgi.sock;
                              fastcgi_index index.php;
                              include fcgi.conf;
                        }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                              expires      30d;
                        }


spectrum 发表于 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 编辑 ]

licess 发表于 2010-5-25 22:47:37

回复 8# 的帖子

直接用./vhost.sh 添加就可以

spectrum 发表于 2010-5-25 23:51:11

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

以下为VHOST.CONF

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;
}以下为NGINX.CONF代码

user www www;

worker_processes 1;

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

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

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

events
{
use epoll;
worker_connections 51200;
}

http
{
include mime.types;
default_type application/octet-stream;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

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 256k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;

server
{
listen 80;
server_name baowang.com;
index index.html index.htm index.php;
root /home/wwwroot/www;

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

location /status {
stub_status on;
access_log off;
}

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

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

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /home/wwwroot/logs/access.log access;
}
include vhost/*.conf;
}我同时参考了张宴的博客: 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 编辑 ]
页: [1]
查看完整版本: 军哥进来,有个VHOST问题请教一下