云服务器编译安装Nginx1.0.15,并建立vhost。




1)下载 nginx 源码包
http://nginx.org/en/download.html

1.png 

2)源码安装nginx
# tar zxvf nginx-1.0.15.tar.gz
# cd nginx-1.0.15
# ./configure --user=www --group=www --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/run/nginx.pid --lock-path=/usr/local/nginx/lock/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module
yum install pcre-devel perl-devel perl-ExtUtils-Embed -y
# make clean
# ./configure --user=www --group=www --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/run/nginx.pid --lock-path=/usr/local/nginx/lock/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module


# make
# make install
# /usr/local/apache/bin/apachectl stop
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf     启动nginx

浏览器测试
2.png 


接下来进行源码安装PHP,请参考下面教程:
http://bbs.qcloud.com/forum.php?mod=viewthread&tid=4346&extra=page%3D1

Nginxphp整合
# vi /usr/local/nginx/conf/nginx.conf
:set nu
将第 35行到79 行注释掉
:35,79 s/^/#/g

在配置文件倒数第二行添加内容:
include /usr/local/nginx/conf/conf.d/*.conf;

创建 vhost配置文件所在的目录
# mkdir /usr/local/nginx/conf/conf.d/
# vi web01.conf
server {
      listen       80;
      server_name www.aaa.com;
      location / {
          root   /var/web01;
          index  index.php index.html index.htm;
      }
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /var/web01;
      }
      location ~ \.php$ {
          root           /var/web01;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /var/web01$fastcgi_script_name;
          include        fastcgi_params;
      }
}

3.png 

# vi web02.conf
server {
      listen       80;
      server_name www.bbb.com;
      location / {
          root   /var/web02;
          index  index.php index.html index.htm;
      }
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   /var/web02;
      }
      location ~ \.php$ {
          root           /var/web02;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /var/web01$fastcgi_script_name;
          include        fastcgi_params;
      }
}


4.png 

创建两个站点的 web目录
# mkdir /var/web01
# mkdir /var/web02


创建测试页面
# echo “web01”  > /var/web01/test01.php
# echo “web02”  > /var/web02/test02.php

本地 host文件设置[url=]www.aaa.com,  www.bbb.com[/url]指向服务器 IP

重启php和nginx
# service php-fpm restart
# ps -ef|grep nginx|awk '{print $2}'|xargs kill -9
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

浏览器测试成功:
5.png

注:此方法不限于腾讯云服务器,百度云服开放云务器,阿里云服务器,传统服务器也适用!
 
北京凯铧互联科技有限公司(简称凯铧互联)由多名前阿里云资深技术专家创立,核心员工来自阿里巴巴、腾讯等,做为一家综合性方案商,凯铧互联向各行业用户提供基于公有云,私有云,混合云等基于云计算的各种解决方案。
本公司销售:阿里云、腾讯云、百度云、天翼云、金山大米云、金山企业云盘!可签订合同,开具发票。
?