LAMP、LNMP实战之三搭建nginx(持续更新)

说明:服务器192.168.2.40
nginx版本nginx-1.6.2.tar.gz

1.安装nginx
注:一般的rpm安装1、.config 2、make && make install流程
yum install lrzsz -y //安装上传、下载工具
yum install gcc -y //安装gcc
yum install pcre pcre-devel -y //安装pcre
yum install openssl openssl-devel -y //安装openssl
mkdir /home/www/tools -p //创建tools目录
cd /home/www/tools //进入tools目录
将nginx-1.6.2.tar.gz压缩包放在此目录
tar zxf nginx-1.6.2.tar.gz //解压nginx
cd nginx-1.6.2 //进入nginx目录
useradd nginx -s /sbin/nologin -M //创建nginx用户
./configure --user=nginx --group=nginx --prefix=/application/nginx1.6.2 --with-http_stub_status_module --with-http_ssl_module //编译
make && make install //编译
ln -s /application/nginx1.6.2/ /application/nginx //创建软连接
/application/nginx/sbin/nginx -t //检查语法
/application/nginx/sbin/nginx //启动nginx
vi /etc/rc.local //编辑开机启动文件,添加以下内容
/application/nginx/sbin/nginx
:wq //保存退出
打开IE浏览器输入服务器网址如果网页显示“Welcome to nginx!”说明安装成功


2.搭建网站
mkdir /var/html/{www,blog,bbs} -p //创建3个目录mkdir /var/html/{www,blog,bbs}/index.html
cd /var/html //进入htmlm目录
touch /var/html/{www,blog,bbs}/index.html //分别在3个目录下创建3个html文件
for name in www blog bbs;do echo "http://$name.zhaojunjian.com" >/var/html/$name/index.html;done //在3个html文件中添加内容
for name in www blog bbs;do cat /var/html/$name/index.html;done //查看是否添加成功
cd /application/nginx/conf //进入conf目录
egrep -v "#|^$" nginx.conf >a.log //删选配置文件内容
cp a.log nginx.conf //覆盖原配置文件
按y
vi nginx.conf //编辑配置文件,改为一下内容

worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.zhaojunjian.com;
root /var/html/www;
index index.php index.html index.htm;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
server {
listen 80;
server_name bbs.zhaojunjian.com;
root /var/html/bbs;
index index.php index.html index.htm;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
server {
listen 80;
server_name blog.zhaojunjian.com;
root /var/html/blog;
index index.php index.html index.htm;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
:wq //保存退出
/application/nginx/sbin/nginx -s reload //重启服务
打开IE输入网址测试是否可正常打开

posted @ 2017-07-12 15:05  51redhet  阅读(190)  评论(0编辑  收藏  举报