- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Nginx 的多站点配置方案由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
当我们有了一个 VPS 主机以后,为了不浪费 VPS 的强大资源(相比共享主机1000多个站点挤在一台机器上),往往有想让 VPS 做点什么的想法,银子不能白花啊:)。放置多个网站或者博客是个不错的想法,可是如何配置 web 服务器才能在一个 VPS 上放置多个网站/博客呢?如何通过一个 IP 访问多个站点/域名呢?这就是大多数 web 服务器支持的 virtual hosting 功能。这里将描述如何一步一步如何用 nginx 配置 virtual hosting.
nginx 是一个小巧高效的 web 服务器,由俄罗斯程序员 Igor Sysoev 开发,nginx 虽然体积小,但功能一点也不弱,能和其他的 web 服务器一样支持 virtual hosting,即一个IP对应多个域名以支持多站点访问,就像一个IP对应一个站点一样,所以是”虚拟”的。你想在一个 IP 下面放多少个站点就放多少,只要硬盘够大就行.
这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:
1
2
3
|
IP地址: 202.55.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2
|
配置 nginx virtual hosting 的基本思路和步骤如下:
把2个站点 example1.com, example2.com 放到 nginx 可以访问的目录 /www/ 给每个站点分别创建一个 nginx 配置文件 example1.com.conf,example2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/ 然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号) 。
重启 nginx 。
具体过程 。
下面是具体的配置过程:
1、在 /etc/nginx 下创建 vhosts 目录 。
mkdir /etc/nginx/vhosts 。
2、在 /etc/nginx/vhosts/ 里创建一个名字为 example1.com.conf 的文件,把以下内容拷进去 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
server {
listen 80;
server_name example1.com www. example1.com;
access_log /www/access_ example1.log main;
location / {
root /www/example1.com; index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example1.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht { deny all; } }
|
3、在 /etc/nginx/vhosts/ 里创建一个名字为 example2.com.conf 的文件,把以下内容拷进去 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
server {
listen 80;
server_name example2.com www. example2.com;
access_log /www/access_ example1.log main;
location /
{
root /www/example2.com; index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example2.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht { deny all; } }
|
4、打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来 。
user nginx; worker_processes 1; # main server error log error_log /var/log/nginx/error.log ; pid /var/run/nginx.pid; events { worker_connections 1024; } # main server config http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; server { listen 80; server_name _; access_log /var/log/nginx/access.log main; server_name_in_redirect off; location / { root /usr/share/nginx/html; index index.html; } } # 包含所有的虚拟主机的配置文件 include /usr/local/etc/nginx/vhosts/*; } 。
5、重启 Nginx 。
/etc/init.d/nginx restart 。
原文链接:http://www.cnblogs.com/gide/p/4437898.html 。
最后此篇关于Nginx 的多站点配置方案的文章就讲到这里了,如果你想了解更多关于Nginx 的多站点配置方案的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
最近我用 php 建立了一个网站,但他们的旧网站都是 HTML 格式的。所以现在我不知道使用 .htaccess 将所有这些旧链接重定向到新站点(可能将所有带有 HTML 的链接重定向到主域)的最佳方
我创建了一个新的 WordPress 网站,它是我旧网站的更名版本。它有一个新的域和一个新的设计。除此之外,其他一切都是相同的,包括内容和链接结构。现在我想完全重定向旧链接。与旧帖子一样,标签和类别
我想使用 WatiN测试我正在开发的网站的功能。理想情况下,我会在测试开始运行之前以编程方式部署网站 (asp.net MVC3),然后在每次测试之前刷新数据。这可能吗? 最佳答案 在此处阅读有关使用
我们的网站使用我们自己定制的 session 状态管理,与 ASP.NET session 状态分开。但是由于少数特殊页面使用 SQL Server Reporting Services,我们还需要启
不久前我看到一个网站,其中有 JavaScript/HTML/CSS 栏目,下面有实际代码的样子。有点像 jsFiddle,但它有用户示例和演示。有谁知道这个网站的名字吗?我到处都找不到它!谢谢! 最
我们的核心数据库出现问题,该数据库已由前一天的备份数据库恢复。 此后,网站工作正常,但我们在发布任何更改时遇到问题。一旦点击发布按钮,“发布正在初始化..”消息就会持续很长时间。截至“发布开始/结束”
我们的核心数据库出现问题,该数据库已由前一天的备份数据库恢复。 此后,网站工作正常,但我们在发布任何更改时遇到问题。一旦点击发布按钮,“发布正在初始化..”消息就会持续很长时间。截至“发布开始/结束”
Maven 不仅仅是一款项目构建和依赖管理工具,它还能够聚合项目信息,促进项目团队间地交流。POM 中可以包含各种项目信息,例如:项目描述、SCM 地址、许可证信息,开发者信息等。用户可以使用 Mav
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭上个月。 Improve this ques
您知道哪些网站正在使用 Silverlight?此信息将帮助我们决定何时采用 Silverlight 平台。 这些网站应该是面向公众的并且被认为是高流量的。 (每月至少 300,000 次点击)。 我
我尝试通过 VS2017 中的发布上下文菜单将我的 .net 核心站点部署到 Azure,偶尔(大约三分之一的部署),我收到以下错误。 Web deployment task failed. (Web
我为 20 个不同的国家/地区创建了一个包含 20 个站点(每个站点一个不同的域)的 Django 项目。这些站点共享所有内容:代码库、数据库、网址、模板等。 他们唯一不共享的是我在每个站点设置文件中
如何将商店页面添加到我使用 jekyll 和基础构建的网站? 任何自动化平台/方法都可以做到这一点。 谢谢。 最佳答案 您可以使用 snipcart .有一个blog post和一个 demo sit
我部署了一个服务结构集群,域为 foo.northcentralus.cloudapp.azure.com 它具有单一节点类型和单一公共(public) IP 地址/负载均衡器。 假设我部署了以下
我不是一个大的typ3 专家,也无法访问我正在使用的typ3 实例中的typoscript 选项(这是一个非常大的站点,我没有这样做的授权)。所以我希望这个问题适合 stackoverflow(如果没
我们正在对我们的 Drupal 站点进行性能调整。 我们正在使用 Siege 来衡量性能(作为 drupal 访问者)。 环境: Nginx + FastCGI + Memcache Siege 运行
我搜索了 SO、SU 和 SP.SE寻求解决方案,但找不到我需要的东西。我正在寻找一个解决方案,它可能是一个脚本或一些其他非编码方法/工具。 我正在尝试编写一个脚本(供其他人使用)或某种其他形式的自动
我有一个 Django 站点,它使用本地化中间件与 gettext 和 trans/blocktrans 模板标签相结合,根据用户代理字符串中的首选语言向访问者显示不同的页面(这似乎是在 Django
我是 Drupal 新手。是否可以设置所有内容并在服务器上部署 Drupal?我的意思是像放入内容、设置模块等...,然后将它们全部放到生产服务器上? 最佳答案 当然。 复制所有文件 编辑数据库凭证(
我想将以下行添加到我的 head.html仅在运行时 jekyll serve本地: 如果可能的话,我正在考虑使用一些简单的液体检查。 最佳答案 当你做 jekyll serve本地默认 {{
我是一名优秀的程序员,十分优秀!