nginx virtual host configuration (2) - ttlsa tutorial series nginx

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
Configure nginx log format, find the following in nginx.conf, and remove the # comment mark
#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
server {}: configuring virtual host must have this section. server_name: virtual host domain name, you can write multiple domain names, similar to an alias, for example, you can configure to server_name b.ttlsa.com c.ttlsa.com d.ttlsa.com, so, to access any domain name, content is the same listen 80, monitor ip and port, here just only port, 80-port server represents the current ip of all, if you only want to listen 127.0.0.1 80, worded as follows: listen 127.0.0.1:80 root / data / site /b.ttlsa.com: the site root directory, where your website files are stored. Note: The site directory and domain name as much as possible, to develop a good habit access_log /data/logs/nginx/b.ttlsa.com-access.log main: access log location / {} default uri, location specific content of the follow-up to explain, we are concerned about . it restart and open the site nginx -t check nginx configuration is ok, the command is as follows:
# /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

Guess you like

Origin blog.csdn.net/weixin_33963189/article/details/91546939