2

nginx一台服务器配置多个站点的配置方法

Posted by 撒得一地 on 2016年6月27日 in nginx笔记

使用ECS产品,可以在单台主机上面搭建多个站点,nginx服务提供了配置基于ip、端口、域名的虚拟主机功能,只要把域名绑定不同的location,然后在指定的路径下上传各个网站的程序即可。

简单介绍一下基于域名的虚拟主机的配置方法:

1. 比如我想建立两个站点的域名分别是www.A.com 和 www.B.com,将这两个域名都解析到自己的服务器ip。

2. 在nginx的配置文件conf目录下创建一个专门存放虚拟主机配置的目录,命名为vhosts_conf,可以把虚拟目录的配置全部放在这里。在里面创建名为vhosts_A.conf和vhosts_B.conf文件并打开,在里面写下相关的配置文件。

配置文件参考:

server { 
listen 80;              #监听的端口号 
server_name A.com;           #域名 
#access_log logs/host.access.log main; 

location / { 
root X:/wnmp/www/A;                #站点的路径 
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/A; 
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; 

3. 在nginx的主配置文件里,设置包含这两个站点的配置文件。

    打开nginx.conf文件,在http{…}段输入

#包含所有的虚拟主机的配置文件 (填写服务器中vhosts_conf/*.conf所在绝对路径)
include X:/nginx/conf/vhosts_conf/*.conf; 

4. 在指定的路径下上传每个站点的数据

5. 重启nginx,测试是否访问正常

上一篇:

下一篇:

相关推荐

2 Comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注

8 + 0 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.