基于nginx的虚拟主机的配置
2013-03-06 01:00
603 查看
安装pcre
tar -xvf pcre-8.32.tar.gz
cd pcre-8.32
./configure
make;make install
安装nginx
首先创建一个nginx用户,以nginx用户来运行nginx
useradd nginx
tar -xvf nginx-1.2.7.tar.gz
cd nginx-1.2.7
./configure --user=nginx --group=nginx
--prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module
make;make install
启动nginx时提示:error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:
32位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64
启动时提示:nginx: [emerg] getpwnam("nginx --group=nginx") failed
解决方法:
把nginx配置文件中的user改为编译时指定的用户即可
1.配置基于主机名的虚拟主机
vi /etc/hosts
192.168.183.138 www.test.com
192.168.183.138 www.a.org
echo "www.test.com" > /web/test/index.html
echo "www.a.org" > /web/test/index.html
修改nginx的配置文件,添加两段主机配置
server {
listen 80;
server_name www.test.com;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.a.org;
location / {
root /web/a/;
index index.html index.htm;
}
}
root用来指定网页根目录
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试:
2.基于端口的虚拟主机配置
修改nginx的配置文件
server {
listen 9090;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 8080;
location / {
root /web/a/;
index index.html index.htm;
}
}
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试
3.配置基于IP地址的虚拟主机
ifconfig eth0:0 192.168.183.139/24
这里我本机的IP地址是192.168.183.138
修改配置文件
server {
listen 192.168.183.138:80;
server_name www.test.com;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 192.168.183.139:80;
server_name www.a.org;
location / {
root /web/a/;
index index.html index.htm;
}
}
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试
本文出自 “成长全记录” 博客,请务必保留此出处http://lymrg.blog.51cto.com/1551327/1148011
tar -xvf pcre-8.32.tar.gz
cd pcre-8.32
./configure
make;make install
安装nginx
首先创建一个nginx用户,以nginx用户来运行nginx
useradd nginx
tar -xvf nginx-1.2.7.tar.gz
cd nginx-1.2.7
./configure --user=nginx --group=nginx
--prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module
make;make install
启动nginx时提示:error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:
32位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64
启动时提示:nginx: [emerg] getpwnam("nginx --group=nginx") failed
解决方法:
把nginx配置文件中的user改为编译时指定的用户即可
1.配置基于主机名的虚拟主机
vi /etc/hosts
192.168.183.138 www.test.com
192.168.183.138 www.a.org
echo "www.test.com" > /web/test/index.html
echo "www.a.org" > /web/test/index.html
修改nginx的配置文件,添加两段主机配置
server {
listen 80;
server_name www.test.com;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.a.org;
location / {
root /web/a/;
index index.html index.htm;
}
}
root用来指定网页根目录
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试:
2.基于端口的虚拟主机配置
修改nginx的配置文件
server {
listen 9090;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 8080;
location / {
root /web/a/;
index index.html index.htm;
}
}
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试
3.配置基于IP地址的虚拟主机
ifconfig eth0:0 192.168.183.139/24
这里我本机的IP地址是192.168.183.138
修改配置文件
server {
listen 192.168.183.138:80;
server_name www.test.com;
location / {
root /web/test/;
index index.html index.htm;
}
}
server {
listen 192.168.183.139:80;
server_name www.a.org;
location / {
root /web/a/;
index index.html index.htm;
}
}
配置文件检测
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
启动nginx /usr/local/nginx/sbin/nginx
测试
本文出自 “成长全记录” 博客,请务必保留此出处http://lymrg.blog.51cto.com/1551327/1148011
相关文章推荐
- nginx配置基于端口和基于IP的虚拟主机
- 基于nginx的虚拟主机的配置
- Nginx配置之基于域名的虚拟主机
- Nginx配置之基于域名的虚拟主机
- Linux实战第八篇:CentOS7.3下Nginx虚拟主机配置实战(基于端口)
- nginx基于域名的虚拟主机实战配置
- Centos7 nginx配置基于多个IP的虚拟主机
- nginx基于域名的虚拟主机配置实战
- Linux实战第七篇:CentOS7.3下Nginx虚拟主机配置实战(基于IP)
- Linux实战第六篇:CentOS7.3下Nginx虚拟主机配置实战(基于域名)
- Nginx配置之基于域名的虚拟主机
- Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试 推荐
- nginx学习笔记之基于端口的虚拟主机基于主机名的虚拟主机root、alias、index配置
- Nginx基于IP,端口,域名配置虚拟主机
- Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试
- nginx配置基于域名的虚拟主机
- Linux实战第五篇:RHEL7.3下Nginx虚拟主机配置实战(基于别名)
- 【Nginx】配置基于域名的虚拟主机
- Nginx配置之基于域名的虚拟主机
- Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试