系统环境:centos6.5
软件包:nginx-1.6.1.tar.gz
一、nginx编码安装:
-
yum install pcre-devel pcre -y
-
cd /tmp
-
wget -c http://nginx.org/download/nginx-1.6.1.tar.gz
-
tar -zxf nginx-1.6.1.tar.gz
-
cd nginx-1.6.1
-
#修改nginx版本信息为ws,其实就是为了不再ie页面不显示nginx的版本。
-
sed -i -e 's/1.6.1//g' -e 's/nginx\//ws/g' -e 's/"nginx"/"ws"/g' src/core/nginx.h
-
useradd www
-
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
-
make
-
make install
-
#检查nginx配置文件是否正确,返回ok为正确。
-
/usr/local/nginx/sbin/nginx -t
-
#指定nginx配置文件
-
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-
#测试指定的nginx配置文件是否正确;
-
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
-
#启动nginx
-
/usr/local/nginx/sbin/nginx
-
#关闭nginx -s stop 快速关闭,不考虑当前是否有请求;
-
/usr/local/nginx/sbin/nginx -s stop
-
#关闭nginx -s quit 退出之前完成已经接受的连接请求;
-
/usr/local/nginx/sbin/nginx -s quit
-
#重新加载修改后的配置
-
/usr/local/nginx/sbin/nginx -s reload
-
#重新打开日志文件;
-
/usr/local/nginx/sbin/nginx -s reopen
-
二、配置多个虚拟主机
1、创建两个虚拟主机站点目录
-
cd /usr/local/nginx/html
-
mkdir v{1,2}
-
for ((i=1;i<=2;i));do touch v${i}/index.html;echo "i am v${i}"'!' > v${i}/index.html;done
-
2、修改nginx.conf,添加虚拟主机配置
/usr/local/nginx/conf/nginx.conf
-
#user nobody;
-
worker_processes 1;
-
events {
-
worker_connections 1024;
-
}
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
sendfile on;
-
keepalive_timeout 65;
-
server {
-
listen 80;
-
server_name localhost
-
-
#charset koi8-r;
-
-
#access_log logs/host.access.log main;
-
-
location / {
-
root html;
-
index index.html index.htm;
-
}
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
}
-
#virtual hosts config
-
server {
-
listen 80;
-
server_name localhost
-
-
#charset koi8-r;
-
-
#access_log logs/host.access.log main;
-
-
location / {
-
root html/v1;
-
index index.html index.htm;
-
}
-
}
-
server {
-
listen 80;
-
server_name localhost
-
-
#charset koi8-r;
-
-
#access_log logs/host.access.log main;
-
-
location / {
-
root html/v2;
-
index index.html index.htm;
-
}
-
}
-
/usr/local/nginx/sbin/nginx -s reload
3、绑定本地hosts文件,ie访问
阅读(1039) | 评论(0) | 转发(0) |