[LNMP]Nginx默认虚拟主机

简介:

    与httpd类似,第一个被Nginx加载的虚拟主机就是默认主机。但与之不同的是,它还有一个配置用来标记默认虚拟主机。

1、编辑nginx.conf

1
2
3
4
5
6
7
8
9
10
11
[root@juispan conf] # vi /usr/local/nginx/conf/nginx.conf
         location ~ \.php$
         {
             include fastcgi_params;
             fastcgi_pass unix: /tmp/php-fcgi .sock;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME  /usr/local/nginx/html $fastcgi_script_name;
         }
     }
include vhost/*.conf;    ##增加改行
}

2、编辑default.conf

1
2
3
4
5
6
7
8
9
[root@juispan conf] # mkdir /usr/local/nginx/conf/vhost
[root@juispan conf] # cd !$;vi default.conf
server
{
     listen 80 default_server;  
     server_name aaa.com;
     index index.html index.htm index.php;
     root  /data/wwwroot/default ;
}

3、检查与启动

1
2
3
4
[root@juispan vhost] #  /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
[root@juispan vhost] #  /usr/local/nginx/sbin/nginx -s reload

4、测试效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@juispan vhost] # mkdir -p /data/wwwroot/default/
[root@juispan vhost] # echo “This is a default site.”>/data/wwwroot/default/index.html
[root@juispan vhost] # curl localhost
<!DOCTYPE html>
<html>
< head >
<title>Welcome to nginx!< /title >
<style>
     body {
         width: 35em;
         margin: 0 auto;
         font-family: Tahoma, Verdana, Arial, sans-serif;
     }
< /style >
< /head >
<body>
<h1>Welcome to nginx!< /h1 >
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.< /p >
 
<p>For online documentation and support please refer to
<a href= "http://nginx.org/" >nginx.org< /a >.<br/>
Commercial support is available at
<a href= "http://nginx.com/" >nginx.com< /a >.< /p >
 
<p><em>Thank you  for  using nginx.< /em >< /p >
< /body >
< /html >
[root@juispan vhost] # curl -x127.0.0.1:80 123.com
“This is a default site.”















本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1955284 ,如需转载请自行联系原作者

相关文章
|
5月前
|
运维 应用服务中间件 Shell
LNMP详解(十六)——Nginx日志切割
LNMP详解(十六)——Nginx日志切割
58 5
|
5月前
|
运维 应用服务中间件 Linux
LNMP详解(十三)——Nginx子页面详解
LNMP详解(十三)——Nginx子页面详解
52 3
|
5月前
|
Web App开发 编解码 运维
LNMP详解(十二)——Nginx URL重写实战
LNMP详解(十二)——Nginx URL重写实战
62 2
|
5月前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
126 2
|
5月前
|
运维 监控 应用服务中间件
LNMP详解(十五)——Nginx日志分析实战
LNMP详解(十五)——Nginx日志分析实战
68 0
|
5月前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
100 0
|
5月前
|
运维 负载均衡 应用服务中间件
LNMP详解(九)——Nginx虚拟IP实战
LNMP详解(九)——Nginx虚拟IP实战
118 2
|
5月前
|
缓存 运维 前端开发
LNMP详解(十)——Nginx负载分担实战
LNMP详解(十)——Nginx负载分担实战
54 1
|
5月前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
68 1
|
2月前
|
应用服务中间件 nginx
Nginx——虚拟主机简介
Nginx——虚拟主机简介
45 0