nginx虚拟主机配置

最近服务器上用的环境是lnmp,之前一直在用apache,配置虚拟主机也是很方便的。今天查资料发现Nginx的虚拟主机配置更加简单。

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server {

listen 80;

server_name domain1;

location / {

root html/domain1;

index index.html index.htm index.php;

}

location ~ \.php$ {

root html/domain1;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

server {

listen 80;

server_name domain2;

location / {

root html/domain2;

index index.html index.htm index.php;

}

location ~ \.php$ {

root html/domain2;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

保存之后,执行

1
nginx -s reload

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×