您的位置:首页 > 运维架构 > Nginx

nginx虚拟主机

2016-03-23 10:24 633 查看
一、编译安装完成nginx在这就不说了,前文有具体的安装过程;

二、排除不需要的内容;
[root@nginx ~]# egrep -v "#|^$" /etc/nginx/nginx.conf >/tmp/nginx.conf

三、修改内容,拷贝到cp /tmp/nginx.conf /etc/nginx/nginx.conf
######################################################################
[root@nginx data]# cat /etc/nginx/nginx.conf
user nginx nginx;
worker_processes 6;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.etangbo.com;
access_log /app/log/www/host.access.log;
location / {
root /data/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
###
server {
listen 80;
server_name bbs.etangbo.com;
access_log /app/log/bbs/host.access.log;
location / {
root /data/bbs;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
###
server {
listen 80;
server_name blog.etangbo.com;
access_log /app/log/blog/host.access.log;
location / {
root /data/blog;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@nginx data]#
######################################################################

四、创建网页文件目录和授权
mkdir /data/www -p
chown -R nginx.nginx /data/www/
mkdir /app/log -p

[root@nginx ~]# /usr/sbin/nginx -s reload # 加载配置文件

五、本地hosts做解析:C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.168.11.32 www.etangbo.com
192.168.11.32 bbs.etangbo.com
192.168.11.32 blog.etangbo.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息