如何配置基于端口的虚拟主机

广告也精彩

应用场景nginx对外提供81和82两个端口监听服务。访问http://192.168.78.132:81端口则请求html81目录下的html请求http://192.168.78.132:82端口则请求html82目录下的html准备环境1. 创建192.168.78.132虚拟机,保证本地电脑和虚拟网络通畅。2. 在192.168.78.132上安装nginx。创建html目录将原来nginx的html目录拷贝两个目录:html81和html82,为了方便测试需要修改每个目录下的index.html内容不一样。配置虚拟主机修改/usr/local/nginx/conf/nginx.conf文件,添加两个虚拟主机,如下:vi

如何配置基于端口的虚拟主机

/usr/local/nginx/conf/nginx.conf#user nobody;worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;#配置虚拟主机server {#监听的ip和端口,配置80listen 80;#虚拟主机名称这里配置ip地址server_name 192.168.101.3;#所有的请求都以/开始,所有的请求都可以匹配此locationlocation / {#使用root指令指定虚拟主机目录即网页存放目录#比如访问http://ip/test.html将找到/usr/local/html3/test.html#比如访问http://ip/item/test.html将找到/usr/local/html3/item/test.htmlroot /usr/local/nginx/html80;#指定欢迎页面,按从左到右顺序查找index index.html index.htm;}}#配置虚拟主机server {listen 8080;server_name 192.168.101.3;location / {root /usr/local/nginx/html8080;index index.html index.htm;}}}测试重新加载配置nginx配置文件,查看端口监听状态:访问http://192.168.78.132:81访问http://192.168.78.132:82以上,就把nginx 基于ip的配置虚拟主机讲完了。后面会继续讲基于域名配置虚拟主机。

 

转载于天翼云知识,如有侵权,请联系删除,谢谢

© 版权声明
广告也精彩

相关文章

广告也精彩

暂无评论

暂无评论...