This section explains If you are using
nginx configure multiple virtual hosts
, that is, we usually say that the configuration of the domain name. Next, we configure two domain name a.ttlsa.com, b.ttlsa.com. If you do not install nginx words, see Section 1:
ttlsa tutorial series nginx - nginx installation (1)
Preparing a site
that we put under unified site / data / site, each site root directory and domain name are the same ,details as follows. New a.ttlsa.com site root
# mkdir -p /data/site/a.ttlsa.com
- New Home index.html a station
# cat /data/site/a.ttlsa.com/index.html
this is a.ttlsa.com!
- New b.ttlsa.com site root
# mkdir -p /data/site/b.ttlsa.com
- New home station b index.html, content such as this is b.ttlsa.com!
# cat /data/site/b.ttlsa.com/index.html
this is b.ttlsa.com!
- New log file directory
# mkdir -p /data/logs/nginx
We talk about unified logs to be stored under / data / logs, is located here nginx logs, so log nginx nginx remain in the current directory. Logs relatively unified storage specification (If you're nervous, you can own way do)
configuration nginx web hosting
- Increase nginx main configuration file nginx.conf
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
- Configuring nginx main configuration file
# vim /usr/local/nginx-1.5.1/conf/nginx.conf
server{
server_name a.ttlsa.com;
listen 80;
root /data/site/a.ttlsa.com;
access_log /data/logs/nginx/a.ttlsa.com-access.log main;
location /
{
}
}
server{
server_name b.ttlsa.com;
listen 80;
root /data/site/b.ttlsa.com;
access_log /data/logs/nginx/b.ttlsa.com-access.log main;
location /
{
}
}
- Configuration explain
# /usr/local/nginx-1.5.1/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.5.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.5.1/conf/nginx.conf test is successful
If you see more than two lines, says ok and successful configuration issues, that we start the next start nginx nginx
# /usr/local/nginx-1.5.1/sbin/nginx
Access a.ttlsa.com, b.ttlsa.com (my side DNS has resolved to 192.168.1.201, in the case of testing, we can release hosts can), bind host as follows: speak the following increases C: \ Windows \ System32 \ Drivers \ etc \ hosts
192.168.1.201 a.ttlsa.com
192.168.1.201 b.ttlsa.com
These are the windows to bind hosts manner, as is the way linux
echo "192.168.1.201 a.ttlsa.com
192.168.1.201 b.ttlsa.com" >> /etc/hosts
Use a browser to access both sites. I am here to access using curl.
[root@ns conf]# curl http://a.ttlsa.com
this is a.ttlsa.com! //a站点内容
[root@ns conf]# curl http://b.ttlsa.com
this is b.ttlsa.com! //b站点内容
Other instructions
- Close nginx
/usr/local/nginx-1.5.1/sbin/nginx -s stop
- Restart nginx
/usr/local/nginx-1.5.1/sbin/nginx -s reload //修改配置之后reload,实际上严格意义来说这不是
Please indicate the source: http: //www.ttlsa.com/html/1571.html
Reproduced in: https: //my.oschina.net/766/blog/211454