nginx配置多个站点使用同一端口
off999 2025-01-08 16:28 38 浏览 0 评论
场景描述
用户在同一台服务器上部署了多个站点,需要使用不同域名的80端口来访问不同的网站
准备事项
- 主机已安装好nginx服务
- 站点文件已上传到主机目录
- 不同域名已解析到主机IP
部署步骤
1、检查/etc/nginx/nginx.conf <span style="color:red">(nginx默认配置文件路径,如果使用其他方式部署,对应部署的其他路径)</span>配置文件,确保文件中包含 include /etc/nginx/conf.d/*.conf;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; #nginx站点配置文件路径
server {
listen 80 default_server; #默认监听端口
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; #默认站点路径
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
2、在目录/etc/nginx/conf.d下面新建website1.conf,website2.conf,文件名可自定义。监听端口都改为80端口并绑定不同的域名,root路径分别配置为不同的站点路径。 website1.conf文件内容:
server {
listen 80; #website1监听端口
server_name one.example.com; #website1绑定域名
root /var/www/html/web1/; #website1站点路径
# Load configuration files for the default server block.
location / {
index index.php index.html index.htm; #站点默认页面
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
website2.conf文件内容:
server {
listen 80; #website2监听端口
server_name two.example.com; #website2绑定域名
root /var/www/html/web2/; #website2站点路径
# Load configuration files for the default server block.
location / {
index index.php index.html index.htm; #站点默认页面
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
3、重启nginx服务,验证不同域名访问效果
相关推荐
- 磁力种子(磁力种子搜索器怎么用)
-
BT的种子是指在BitTorrent文件分享协议中的一个文件或者目录,其中包含有一个或多个文件的元数据,例如文件名、大小、哈希值等信息。一个种子文件可以看做是一个索引,用来描述一个或多个文件的组成和布...
- windows图片查看器无法显示此图片
-
是因为没有正确配置Windows颜色系统默认设备文件造成的,解决该问题的具体步骤是:打开控制面板,查看方式选择“大图标”,单击打开“颜色管理”对话框,单击选中“高级”选项卡,将Windows颜色系统设...
- 深度技术的win7系统怎么样(深度技术win7系统怎么安装教程)
-
所谓的纯净的win7系统应该说的就是原版的win7系统,相对于Ghost版的系统来说,原版的win7系统是微软发布的未经过第三方修改过的纯净版系统,安装好后,它所有的功能和软件都是微软官方的,不会添加...
- 电脑怎么安全模式开机(电脑怎么安全模式开机启动)
-
电脑开机后进入安全模式的步骤如下:重启电脑:在开机时,狂按F8键,即可进入启动菜单选择界面。选择安全模式:在启动菜单选择界面中,可以看到三个版本的安全模式可以选择,方向键上下调整,然后按下回车键即可。...
- win10企业版长期服务版(win10企业版 长期服务版)
-
Windows10企业版和企业长期服务版是微软为企业用户提供的两个版本,二者主要区别如下:1.版本周期不同。企业版(Enterprise)每年更新两次,每个版本的支持期限仅为18个月,而企业长期服...
- mercury管理页面网址(mercury设置网址是什么)
-
要进入mercury路由器的管理页面,首先需要将电脑与路由器连接,确保网络连接正常。接着在浏览器中输入路由器的默认IP地址(通常为192.168.1.1),按下回车键。输入用户名和密码(默认用户名和密...
- qq手机版官方(qq手机版官方免费下载安装)
-
z.qq.com可以通过以下方式登录手机QQ空间:1、使用手机登录手机腾讯网3g.qq.com,点击“空间”,根据提示QQ号码和QQ密码就可以登录;2、通过手机直接输入手机QQ空间网址z.qq.co...
- w7旗舰版系统怎么恢复出厂设置啊
-
方法一:1、左键单击任务栏开始按钮2、在启动项菜单右侧找到“控制面板”并左键单击3、在打开的界面中找到“区域和语言”选项并左键单击4、在弹出窗口中选择“键盘和语言”,在“选择显示语言”下...
- ubuntu下载安装(Ubuntu下载安装包)
-
要在Ubuntu上从官方网站下载和安装Evolution,您可以按照以下步骤进行操作:1.打开您的网页浏览器,访问Ubuntu的官方网站:https://ubuntu.com。2.点击页面顶部的“...
- 联想显示器售后服务电话(lenovo人工客服24小时)
-
联想显示器保修期限在1~2年之内,一,联想“三包”服务承诺联想按国家有关部门颁布的《微型计算机商品修理更换退货责任规定》(以下称“三包”规定)中的内容和范围,向用户提供“三包”服务。联想承担法定“...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
python入门到脱坑 输入与输出—str()函数
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
失业程序员复习python笔记——条件与循环
-
系统u盘安装(win11系统u盘安装)
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
