当前位置: 首页 > news >正文

做一个小说网站需要多少钱成都网站建设公司

做一个小说网站需要多少钱,成都网站建设公司,wordpress跟随按钮怎么做,银川网站制作报价🏡作者主页:点击! Nginx-从零开始的服务器之旅专栏:点击! 🐧Linux高级管理防护和群集专栏:点击! ⏰️创作时间:2025年1月15日13点14分 目录 1. 基于域名的虚拟主机 …

🏡作者主页:点击! 

Nginx-从零开始的服务器之旅专栏:点击!

🐧Linux高级管理防护和群集专栏:点击!

⏰️创作时间:2025年1月15日13点14分


目录

1. 基于域名的虚拟主机

步骤 1:准备网站根目录

步骤 2:修改 Nginx 配置文件

步骤 3:测试配置并重启 Nginx

步骤 4:访问测试

客户端测试

2. 基于 IP 的虚拟主机

步骤 1:准备网站根目录

步骤 2:修改 Nginx 配置文件

步骤 3:测试配置并重启 Nginx

步骤 4:访问测试

客户端测试

3. 基于端口的虚拟主机

步骤 1:准备网站根目录

步骤 2:修改 Nginx 配置文件

步骤 3:测试配置并重启 Nginx

步骤 4:访问测试

客户端测试

4.总结


Nginx 是一款高性能的 Web 服务器,支持多种虚拟主机配置方式,能够根据域名、IP 或端口区分不同的站点。这种灵活性让 Nginx 成为搭建多站点服务的首选工具。本文将带你一步步实现三种常见的虚拟主机配置方法:基于域名、基于 IP 和基于端口的虚拟主机。无论你是初学者还是有经验的运维人员,这篇教程都能帮助你快速掌握虚拟主机的配置技巧。

以下案例演示 是基于源码包安装的nignx (如果你是rpm包 也差不多 只用把路径改为你nginx的路径即可 其他没什么大的变化,如果你是小白请绕道!)

1. 基于域名的虚拟主机

步骤 1:准备网站根目录

为每个域名创建独立的子目录,并添加测试页面:

[root@localhost ~]# mkdir -p /usr/local/nginx/html/site1
[root@localhost ~]# mkdir -p /usr/local/nginx/html/site2[root@localhost ~]# echo "Welcome to Site 1" > /usr/local/nginx/html/site1/index.html
[root@localhost ~]# echo "Welcome to Site 2" > /usr/local/nginx/html/site2/index.html

步骤 2:修改 Nginx 配置文件

打开 Nginx 的配置文件:

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

http 配置段中添加以下内容:

注释:如果需要两个虚拟主机 只用将再额外添加一个server即可

# 全局配置
user  nobody;
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.site1.com;# 网站根目录root   html/site1;index  index.html index.htm;# 日志配置access_log  logs/site1_access.log;error_log   logs/site1_error.log;# 主路径配置location / {try_files $uri $uri/ =404;}# 状态监控location /status {stub_status on;access_log off;allow 192.168.14.112;deny all;}# 错误页面配置error_page   404              /404.html;error_page   500 502 503 504  /50x.html;location = /404.html {root   html/site1;}location = /50x.html {root   html;}# 禁止访问 .ht 文件location ~ /\.ht {deny all;}}server {listen       80;server_name  www.site2.com;# 网站根目录root   html/site2;index  index.html index.htm;# 日志配置access_log  logs/site2_access.log;error_log   logs/site2_error.log;# 主路径配置location / {try_files $uri $uri/ =404;}# 错误页面配置error_page   404              /404.html;error_page   500 502 503 504  /50x.html;location = /404.html {root   html/site2;}location = /50x.html {root   html;}# 禁止访问 .ht 文件location ~ /\.ht {deny all;}}
}

步骤 3:测试配置并重启 Nginx

测试配置文件语法:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

重启 Nginx 服务:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

步骤 4:访问测试

在浏览器中访问:

  • http://www.site1.com,应显示 Welcome to Site 1
  • http://www.site2.com,应显示 Welcome to Site 2

客户端测试

修改hosts文件(本地dns解析)

[root@localhost ~]# vim /etc/hosts

2. 基于 IP 的虚拟主机

步骤 1:准备网站根目录

为每个 IP 创建独立的子目录,并添加测试页面:

[root@localhost ~]# mkdir -p /usr/local/nginx/html/ip1
[root@localhost ~]# mkdir -p /usr/local/nginx/html/ip2[root@localhost ~]# echo "Welcome to IP 192.168.14.111" > /usr/local/nginx/html/ip1/index.html
[root@localhost ~]# echo "Welcome to IP 192.168.14.112" > /usr/local/nginx/html/ip2/index.html

步骤 2:修改 Nginx 配置文件

打开 Nginx 的配置文件:

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

http 配置段中添加以下内容:

server {listen 192.168.14.111:80;server_name 192.168.14.111;root html/ip1;  # 使用默认路径的子目录index index.html;location / {try_files $uri $uri/ =404;}# 错误页面error_page 500 502 503 504 /50x.html;location = /50x.html {root html;  # 默认错误页面路径}
}server {listen 192.168.14.112:80;server_name 192.168.14.112;root html/ip2;  # 使用默认路径的子目录index index.html;location / {try_files $uri $uri/ =404;}# 错误页面error_page 500 502 503 504 /50x.html;location = /50x.html {root html;  # 默认错误页面路径}
}

步骤 3:测试配置并重启 Nginx

测试配置文件语法:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

重启 Nginx 服务:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

步骤 4:访问测试

在浏览器中访问:

  • http://192.168.14.111,应显示 Welcome to IP 192.168.14.111
  • http://192.168.14.112,应显示 Welcome to IP 192.168.14.112

客户端测试

因为我在虚拟机测试 只有一个网卡 所以我在虚拟一个网卡 这个你可以忽视 看测试结果即可

 ip addr add 192.168.14.110/24 dev ens33

3. 基于端口的虚拟主机

步骤 1:准备网站根目录

为每个端口创建独立的子目录,并添加测试页面:

[root@localhost ~]# mkdir -p /usr/local/nginx/html/port1
[root@localhost ~]# mkdir -p /usr/local/nginx/html/port2[root@localhost ~]# echo "Welcome to Port 8080" > /usr/local/nginx/html/port1/index.html
[root@localhost ~]# echo "Welcome to Port 9090" > /usr/local/nginx/html/port2/index.html

步骤 2:修改 Nginx 配置文件

打开 Nginx 的配置文件:

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

http 配置段中添加以下内容:

server {listen 8080;server_name localhost;root html/port1;  # 使用默认路径的子目录index index.html;location / {try_files $uri $uri/ =404;}# 错误页面error_page 500 502 503 504 /50x.html;location = /50x.html {root html;  # 默认错误页面路径}
}server {listen 9090;server_name localhost;root html/port2;  # 使用默认路径的子目录index index.html;location / {try_files $uri $uri/ =404;}# 错误页面error_page 500 502 503 504 /50x.html;location = /50x.html {root html;  # 默认错误页面路径}
}

步骤 3:测试配置并重启 Nginx

测试配置文件语法:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

重启 Nginx 服务:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

步骤 4:访问测试

在浏览器中访问:

  • http://192.168.14.111:8080,应显示 Welcome to Port 8080
  • http://192.168.14.111:9090,应显示 Welcome to Port 9090

客户端测试

4.总结

通过本文的详细步骤,我们成功实现了基于域名、IP 和端口的虚拟主机配置。Nginx 的灵活性和高性能使其能够轻松应对多站点服务的需求。这些配置方法不仅适用于日常开发和测试环境,也能在生产环境中提供稳定可靠的服务。如果你对 Nginx 的配置还有疑问或其他需求,欢迎留言交流,让我们共同学习、共同进步!

成功的路上没有捷径,只有不断的努力与坚持。如果你和我一样,坚信努力会带来回报,请关注我,点个赞,一起迎接更加美好的明天!你的支持是我继续前行的动力!"

"每一次创作都是一次学习的过程,文章中若有不足之处,还请大家多多包容。你的关注和点赞是对我最大的支持,也欢迎大家提出宝贵的意见和建议,让我不断进步。"

神秘泣男子

http://www.yayakq.cn/news/255412/

相关文章:

  • 哪个网站可以做高数题做母婴的网站
  • 餐饮加盟网站怎么做想要接网站业务如何做
  • 哪家微网站建设国内个人网站搭建
  • 保定网站制作价格表单标签wordpress
  • 2020给个免费网站好人有好报网站logo衔接
  • 做3ds磁铁卡网站传统企业公司网站优化案例
  • 代理网站是什么北京网站建设机构
  • 站长之家论坛南充房产网最新楼盘最近房价
  • 可视化拖拽网站建设软件网页开发文档模板
  • 北京高端网站建设公司浩森宇特佛山外贸网站制作公司
  • 南平摩托车罚款建设网站缴费电子科技网站建设
  • 百度站长平台删站学院网站建设的现状分析
  • 广州市海珠区建设局网站网站 服务器 域名
  • 陕西找人做网站多少钱泰州网站建设优化
  • 怎么做微信推送 网站网站推广主要方法
  • 如何创建一个和淘宝一样的网站专业管网建设服务
  • 福州企业做网站微信公众号售卖
  • 张家港手机网站制作济南营销型网站建设工作室
  • 新加坡建设局网站百度资讯
  • 企业在网站建设中需要做什么中国商标官网入口
  • 网站多域名怎么做个人信息查询
  • 国内网站都要备案吗云主机怎么上传网站
  • 深圳光明建设局官方网站wordpress 防下载
  • 网站开发支付宝支付杭州微信网站建设
  • 有限公司在线网站企业网络营销
  • 空间购买后打不开网站wordpress文本框
  • 广告发布网站开发网站备案查询工信部app
  • 国外网站卖货平台做淘宝网站目的是什么
  • 西安响应式网站建设服务提供商唐山市住建局官方网站
  • 如何制作企业网站的版式宜飞思工业设计网站