温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2022-10-19 14:08:07 来源:亿速云 阅读:135 作者:iii 栏目:建站服务器

这篇文章主要介绍“nginx基于端口如何配置虚拟主机”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“nginx基于端口如何配置虚拟主机”文章能帮助大家解决问题。

一、创建网站目录及文件:

[root@localhost data]# tree /data /data └── wwwroot     ├── www.1.com_8080     │   └── index.html     └── www.1.com_8081         └── index.html

二、修改nginx.conf:

[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf worker_processes  1; events {     worker_connections  1024; } http {     include       mime.types;     default_type  application/octet-stream;     keepalive_timeout  65;     include vhost/*.conf;   #vhost目录下会包含所有的虚拟主机的配置文件 }

三、创建虚拟主机的配置文件目录:

[root@localhost conf]mkdir /usr/local/nginx/conf/vhost

四、创建虚拟主机配置文件:

[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.1.com.8080.conf  server{     listen 8080;     server_name 1.com www.1.com;     index index.html;     root /data/wwwroot/www.1.com_8080; }
[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.1.com.8081.conf   server{     listen 8081;     server_name 1.com www.1.com;     index index.html;     root /data/wwwroot/www.1.com_8081; }
[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/default.conf           server{     listen 80 default_server;  #使用default_server指定nginx的默认虚拟主机     deny all; }

若使用其他域名来访问虚拟主机时,会匹配到默认虚拟主机,该配置会拒绝未定义的域名的虚拟主机。若不配置该选项,默认排在最前边的server会成为默认虚拟主机。

五、测试配置文件是否存在问题:

[root@localhost root]# cd /usr/local/nginx/sbin [root@localhost sbin]# ./nginx -t  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file

六、当配置文件修改时,可以使用一下命令重新加载配置文件

[root@localhost sbin]# ./nginx -s reload

关于“nginx基于端口如何配置虚拟主机”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI