nginx 多站点配置方法
关于nginx的多站设置,其实和apache很相似哒。
假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com。并且这两个域名已经映射给了IP为192.168.1.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了。
2、在nginx的主配置文件里,包含这两个站点的配置文件。
我们打开conf目录下的nginx.conf文件,很容易做,只要在http{...}段输入以下代码:
|
#包含所有的虚拟主机的配置文件 include X:/wnmp/nginx/conf/vhosts_conf/*.conf; |
这样,nginx的多站点配置就做好了,怎么样打开浏览器测试一下吧~
nginx 多站点配置方法的更多相关文章
- nginx 多站点配置方法集合(转)
关于nginx的多站设置,其实和apache很相似,假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com.并且这两个域名已经映射给了IP为192.168. ...
- nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- WAMPServer多站点配置方法
WAMPServer多站点配置方法:1.在C:\wamp\www 新建文件夹test01,在里面新建index.php,内容为 "Hello Test01". 2.C:\wamp\ ...
- php ci nginx 伪静态rewrite配置方法
php ci nginx 伪静态rewrite配置方法 location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$ ...
- 通过浏览器查看nginx服务器状态配置方法
通过浏览器查看nginx服务器状态配置方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了通过浏览器查看nginx服务器状态配置方法,本文讲解开启nginx-status的配 ...
- 二、Nginx多站点配置(参考宝塔的)分析
一.基于宝塔配置文件分析(站的配置文件) 新增的站点配置即添加server并包含在nginx内 查找文件: 文件内容: 二.伪静态 伪静态是一种可以把文件后缀改成任何可能的一种方法,如果我想把php文 ...
- Ubuntu系统下lnmp环境搭建和Nginx多站点配置
最近需要使用Ubuntu作为服务器搭建Lnmp环境,顺便将操作过程写下来,与大家分享.如有不足之处,欢迎大家提出不同意见.(本文默认读者已经熟悉相关linux命令的使用,比如创建文件和文件夹,编辑文件 ...
- Wampserver 2.5 多站点配置方法
写在开头:本文适用于wampserver2.5版本,和wamp的老版本配置有语法上的区别,笔者正是因为被老版本的配置办法给整迷糊了所以才总结了一篇针对2.5版本的配置方法,如果您还停留在1.x或着已经 ...
- 一、Nginx多站点配置
一.下载 目录文件: 二.运行方式 (1)直接双击nginx.exe,双击后一个黑色的弹窗一闪而过 (2)打开cmd命令窗口,切换到nginx解压目录下,输入命令 nginx.exe 或者 start ...
随机推荐
- mysql优化之连接优化
Posted by Money Talks on 2012/02/23 | 第一篇 序章第二篇 连接优化第三篇 索引优化第四篇 查询优化第五篇 到实战中去 连接优化 连接优化主要指客户端连接数据库以及 ...
- 如何在 Objective-C 的环境下实现 defer
关注仓库,及时获得更新:https://github.com/draveness/iOS-Source-Code-Analyze Follow: https://github.com/Dravenes ...
- ssh-add命令
ssh-add命令是把专用密钥添加到ssh-agent的高速缓存中.该命令位置在/usr/bin/ssh-add ➜ ydoc git:(v2.0.0) ✗ sudo ssh-add ~/.ssh/i ...
- Android学习之Intent传递数据
Intent在Activity中的作用主要是有两个: 1.启动目标Activity 2.传递数据 Intent在传递数据时分两种情况:向下一个Activity传递数据和从下一个Activity返回数据 ...
- Atom编辑器入门到精通(一) 安装及使用基础
为什么选择使用Atom Atom是GitHub推出的一款编辑器,被称为21世纪的黑客编辑器,主要的特点是现代,易用,可定制.我之前用过多款编辑器,现在来总结一下个人对各编辑器的看法: Vim是我用的时 ...
- YII中的表单挂件
利用助手(widget)在页面实现表单 控制器中 <?php class YiiFormController extends Controller { public function actio ...
- Android中去掉标题栏的3种方法
1.在java代码中 (SplashActivity继承AppCompatActivity时无效)
- ios UIWebview本地加载H5网页
注意两点 1.拖动文件到工程中选择create folder,文件夹为蓝色 --不要让文件参与编译,而只是让文件加入进来 2.加载方式pathforresorth oftype indire ...
- System V 消息队列
3.1 概述 消息队列结构: struct msqid_ds { struct ipc_perm msg_perm; //权限结构 struct msg *msg_first; //队列中第一个消息 ...
- php安装中的错误
http://www.cnblogs.com/kristain/articles/3809243.html 借鉴php安装错误 2013-01-04 19:16:49 分类: 系统运维 环境: ...