网站首页 > 技术教程 正文
场景描述
用户在同一台服务器上部署了多个站点,需要使用不同域名的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服务,验证不同域名访问效果
- 上一篇: 从一份配置清单详解Nginx服务器配置
- 下一篇: 蓝易云 - nginx常用配置教程。(蓝云易趋)
猜你喜欢
- 2024-10-10 Nginx 实践:location 路径匹配(nginx中location配置)
- 2024-10-10 常规服务器环境怎么搭建及项目部署
- 2024-09-14 Nginx中location块配置入门(nginx location /api)
- 2024-09-14 决定努力学Nginx/OpenResty详解,location路由规则配置详解了
- 2024-09-14 [译]如何配置Nginx(nginx配置cgi)
- 2024-09-14 蓝易云 - Nginx常用配置及和基本功能详解!
- 2024-09-14 基于centos7系统yum安装nginx服务
- 2024-09-14 蓝易云 - nginx常用配置教程。(蓝云易趋)
- 2024-09-14 从一份配置清单详解Nginx服务器配置
- 2024-09-14 Nginx 如何配置 SSL(nginx如何配置ssl)
你 发表评论:
欢迎- 最近发表
-
- Linux新手必看:几种方法帮你查看CPU核心数量
- linux基础命令之lscpu命令(linux中ls命令的用法)
- Linux lscpu 命令使用详解(linux常用ls命令)
- 如何查询 Linux 中 CPU 的数量?这几个命令要知道!
- 在linux上怎么查看cpu信息(linux如何查看cpu信息)
- 查看 CPU 的命令和磁盘 IO 的命令
- 如何在CentOS7上改变网卡名(centos怎么改网卡名字)
- 网工必备Linux网络管理命令(网工必备linux网络管理命令是什么)
- Linux 网络命令知多少(linux 网络 命令)
- Linux通过命令行连接wifi的方式(linux命令行连接无线网)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)