网站首页 > 技术教程 正文
概述
关于nginx的多站设置,其实和apache很相似哒。
假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com。并且这两个域名已经映射给了IP为192.168.1.1的服务器。
为我们的站点创建配置文件
我是这么做的,在nginx的配置文件conf目录下创建一个专门存放VirtualHost的目录,命名为vhosts_conf,可以把虚拟目录的配置全部放在这里。在里面创建名为vhosts_modoupi_websuitA.conf的配置文件并打开,我们在这里做配置,往里面写:
server { listen 80; #监听的端口号 server_name websuitA.com; #域名 #access_log logs/host.access.log main; location / { root X:/wnmp/www/websuitA; #站点的路径 index default.php index.php index.html index.htm; #站点的rewrite在这里写 rewrite ^/(\w+)\.html$ /$1.php; rewrite ^/(\w+)/(\w+)$ /$1/$2.php; } #错误页的配置 error_page 404 /error.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root X:/wnmp/www/websuitA; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
这样就做好了,站点A的配置,同样的方法,做websuitB的配置,这里我命名为vhosts_modoupi_websuitB.conf
server { listen 80; #监听的端口号 server_name websuitB.com; #域名 #access_log logs/host.access.log main; location / { root X:/wnmp/www/websuitB; #站点的路径 index default.php index.php index.html index.htm; #站点的rewrite在这里写 rewrite ^/(\w+)\.html$ /$1.php; rewrite ^/(\w+)/(\w+)$ /$1/$2.php; } #错误页的配置 error_page 404 /error.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { root X:/wnmp/www/websuitB; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
这样,两个站点的配置就OK了。
在nginx的主配置文件里,包含这两个站点的配置文件
我们打开conf目录下的nginx.conf文件,很容易做,只要在http{...}段输入以下代码:
#包含所有的虚拟主机的配置文件 include X:/wnmp/nginx/conf/vhosts_conf/*.conf;
这样,nginx的多站点配置就做好了,怎么样打开浏览器测试一下吧~
后面小编会分享更多运维干货,感兴趣的朋友走一波关注哩~
猜你喜欢
- 2024-10-13 Nginx搭建Maven Repository(Nginx搭建流媒体服务器)
- 2024-10-13 Nginx实现数据库负载均衡(nginx 数据库)
- 2024-10-13 配置Nginx+uwsgi更方便地部署python应用
- 2024-10-13 Nginx + Apache搭建WEB站点(nginx,apache)
- 2024-09-28 OpenWrt-nginx配合dnsmasq架设多个本地网站(以aria2为例)
- 2024-09-28 2.2w Star,这是一款什么样的Nginx可视化配置神器?
- 2024-09-28 一个服务器多个域名网站配置(一个服务器部署多个网站)
- 2024-09-28 Nginx从入门到放弃02-Nginx基本命令和新建WEB站点
- 2024-09-28 Php多版本安装(php5.2.17安装教程)
- 2024-09-28 使用 Nginx 搭个静态站点:Linux 任务驱动
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (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)
本文暂时没有评论,来添加一个吧(●'◡'●)