Nginx虚拟主机
Posted hulue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx虚拟主机相关的知识,希望对你有一定的参考价值。
五、虚拟主机
1、基于域名
编辑nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.hello.com; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
创建域名对应的站点目录及文件
#创建目录 mkdir /appliction/nginx/html/www -p #创建文件 echo "http://www.hello.com" > /appliction/nginx/html/www/index.htm
检查修改过的nginx配置文件语法是否正确
#执行 /appliction/nginx/sbin/nginx -t #返回信息 nginx: the configuration file /appliction/nginx-1.14.0//conf/nginx.conf syntax is ok nginx: configuration file /appliction/nginx-1.14.0//conf/nginx.conf test is successful #没有问题重启nginx(reload平滑重启) /appliction/nginx/sbin/nginx -s reload #检查nginx启动是否正常 ps -ef|grep nginx #检查端口 netstat -lnt|grep 80 ##客户端访问需要在hosts文件内做解析
添加多个虚拟主机
#只需要配置多个server,和对应的页面文件路径 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.hello.com; location / { root html/hello; index index.html index.htm; } } server { listen 80; server_name www.world.com; location / { root html/world; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
创建对应的文件和目录 mkdir /appliction/nginx/html/hello -p echo "http://www.hello.com" > /appliction/nginx/html/hello/index.htm mkdir //appliction/nginx/html/world -p echo "http://www.world.com" > /appliction/nginx/html/world/index.htm
/appliction/nginx/sbin/nginx -s reload
以上是关于Nginx虚拟主机的主要内容,如果未能解决你的问题,请参考以下文章
nginx.conf 忽略了 nginx-ingress 配置映射片段
在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途