安装Nginx
…
…
配置虚拟域名
用一个例子来说明:要给项目文件夹为 /Users/phoenix/Web/HTMLhttp/ 的项目配置虚拟域名为 http://html.server.cn
在 /etc/hosts 文件里添加
1
127.0.0.1 html.server.cn
在 nginx.conf 文件里添加(我的nginx.conf文件在
/usr/local/etc/nginx目录下)1
2
3
4
5
6
7
8
9
10
11
12
13http {
...
//添加以下代码
server {
listen 80;
server_name html.server.cn;
root /Users/phoenix/Web/HTMLhttp/;
location / {
index index.php index.html index.htm;
}
}
}或者(我更推荐的方式)
在/usr/local/etc/nginx目录下新建一个文件夹servers,接着在servers文件夹下新建一个配置文件 mynginx.conf (文件名可自定义)
在 mynginx.conf 文件里添加配置1
2
3
4
5
6
7
8server {
listen 80;
server_name html.server.cn;
root /Users/phoenix/Web/HTMLhttp/;
location / {
index index.php index.html index.htm;
}
}然后在 nginx.conf 配置文件里引用 mynginx.conf 配置
1
2
3
4
5http {
...
include servers/mynginx.conf; // 新增这行代码
}