前面也有关于Nginx的安装讲解,这里再安装一次,这次我就直接把命令打出来了~
[root@localhost ~]# yum -y install pcre-devel zlib-devel wget gcc gcc-c++
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
[root@localhost ~]# wget http://nginx.org/download/nginx-1.6.0.tar.gz
[root@localhost ~]# tar zxvf nginx-1.6.0.tar.gz
[root@localhost ~]# cd nginx-1.6.0
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install
[root@localhost nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.6.0]# ls -l /usr/local/sbin/nginx
lrwxrwxrwx. 1 root root 27 12月 11 22:36 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
[root@localhost ~]# cd && nginx && netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21297/nginx
全新的Nginx已经搭建完成!
- 咱们先切换工作目的到nginx根目录下
[root@localhost ~]# cd /usr/local/nginx/
咱们现在先做基于域名的虚拟主机
(新手建议大家编辑的时候先CP一份配置文件:cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.BAK)
基于域名虚拟主机
然后分别创建两个目录的网页目录已经默认文档
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# mkdir linux-me1.com linux-me2.com
[root@localhost html]# echo "this is linux-me1.com >> 第一个虚拟主机!!!" >> linux-me1.com/index.html
[root@localhost html]# echo "this is linux-me2.com >> 第二个虚拟主机!!!" >> linux-me2.com/index.html
好了文件都准备好了,下面我们还需要改一下本机的hosts文件,因为这两个域名都不是我的。
C:\Windows\System32\drivers\etc\hosts (使用记事本就修改就行了)
然后分别访问两个域名测试
基于端口的虚拟主机
基于IP的虚拟主机
注意每次更改完nginx配置文件需要reload重新加载一下。
原创文章,作者:admin,如若转载,请注明出处:《Nginx-应用篇之虚拟主机配置》http://blog.linux-me.com/system/132.html
最新评论