shallow丿ove
默认虚拟主机
- vi /usr/local/nginx/conf/nginx.conf include vhost/*.conf
- mkdir /usr/local/nginx/conf/vhost
- cd !$ ; vi default.conf server { listen 80 default_server; #标记为默认虚拟主机 server_name aaa.com index index.html index.htm index.php;; root /data/wwwroot/default; }
- mkdir -p /data/wwwroot/default/
- echo "This is a default site." > /data/wwwroot/default/index.html
- /usr/local/nginx/sbin/nginx -t
- /usr/local/nginx/sbin/nginx -s reload
- curl localhost
- curl -x 127.0.0.1:80 123.com
[root@localhost conf]# vi nginx.conf
36 fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
37 fastcgi_intercept_errors on;
38 tcp_nodelay on;
39 gzip on;
40 gzip_min_length 1k;
41 gzip_buffers 4 8k;
42 gzip_comp_level 5;
43 gzip_http_version 1.1;
44 gzip_types text/plain application/x-javascript text/css text/htm
45 application/xml;
46 include vhost/*.conf;
47 }
将 46 server 47 { 48 listen 80; 49 server_name localhost; 50 index index.html index.htm index.php; 51 root /usr/local/nginx/html; 52 location ~ .php$ 53 { 54 include fastcgi_params; 55 fastcgi_pass unix:/tmp/php-fcgi.sock; 56 fastcgi_index index.php; 57 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; 58 } 59 } 改为include vhost/*.conf;
[root@localhost conf]# pwd
/usr/local/nginx/conf
[root@localhost conf]# mkdir vhost
[root@localhost conf]# cd vhost/
[root@localhost vhost]# vi aaa.com.conf
1 server
2 {
3 listen 80 default_server;
4 server_name aaa.com;
5 index index.html index.htm index.php;
6 root /data/wwwroot/default;
7 }
[root@localhost vhost]# mkdir /data/wwwroot/default [root@localhost vhost]# cd !$ cd /data/wwwroot/default [root@localhost default]# vi index.html 1 This is the default site. [root@localhost default]# /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@localhost default]# /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@localhost default]# curl localhost This is the default site. [root@localhost default]# curl -x 127.0.0.1:80 aaa.com This is the default site. [root@localhost default]# curl -x 127.0.0.1:80 bbb.com This is the default site.
> 通过vost目录中查找位于第一个文件为默认虚拟主机访问的页面
---