最近在研究将ecshop转移到nginx下。是为了让ecshop在nginx下更加的发挥自己的特长。提高运行效率。上章我们讲述了如何安装php+mysql+nginx+fascgi。本章我们将结合ecshop+centos+nginx来谈谈如何在nginx下建立虚拟主机。首先我们来分析下nginx.conf
这个是nginx下面的主要配置文件。如果这个文件没配置好,那么nginx将运行不起来。我们修改了nginx.conf之后我们可以通过./nginx -t来测试下nginx是否生效了。
nginx.conf主要有以下几个方面组成。
user nginx;这个指的是nginx下的用户组,默认是使用用户
如果我们需要在nginx下新增加虚拟主机怎么办,那么很简单。我们必须将server复制几个。把主要的数据填写进来。
server {
limit_conn addr 10;
listen 80;
server_name _;
root /opt/www;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
# root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
# root /usr/share/nginx/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 $document_root$fastcgi_script_name;
# include fastcgi_params;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
首先要定义root目录。这个是工作目录,我们可以自己在所有的环节面前定义root /opt/www,然后其他环节里面的root都可以注释掉了。比如404页面,你也要在root里面定义。
error_page 404 /404.html;
location = /404.html {
# root /usr/share/nginx/html;
}
如果想nginx执行fastcgi。就必须调用fastcgi.conf里面的变量。
include fastcgi.conf;
我们通过以上方式就可以了。