在Nginx服务器中设置多个站点
这里以配置1个站点(1个域名)为例,n 个站点可以相应增加调整,
假设:
IP地址: 127.0.0.1
域名1 phpmyadmin.zhengwen.cn 放在 /www/phpmyadmin.zhengwen.cn
配置 nginx virtual hosting 的基本思路和步骤如下:
把站点 phpmyadmin.zhengwen.cn 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 phpmyadmin.zhengwen.cn.conf,
并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx
具体过程 
下面是具体的配置过程:
1、在 /etc/nginx 下创建 vhosts 目录
mkdir /etc/nginx/vhosts
2、在 /etc/nginx/vhosts/ 里创建一个名字为 phpmyadmin.zhengwen.cn.conf 的文件,把以下内容拷进去
server{
    listen 80;
    server_name phpmyadmin.zhengwen.cn;
    access_log /www/phpmyadmin.zhengwen.cn.log main;
    location /{
        root /www/phpmyadmin.zhengwen.cn;
        index index.php default.php index.html;
    }
    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/phpmyadmin.zhengwen.cn/$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~/\.ht {
        deny all;
    }
}
3、打开/etc/nginx/conf.d/default.conf 文件,在相应位置加入 include 把以上1个文件包含进来
# 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/*;
}
4、重启 Nginx
/etc/init.d/nginx restart
参考:http://www.server110.com/nginx/201309/981.html
在Nginx服务器中设置多个站点的更多相关文章
- Nginx服务器中配置非80端口的端口转发方法详解
		这篇文章主要介绍了Nginx服务器中配置非80端口的端口转发方法详解,文中使用到了Nginx中的proxy_pass配置项,需要的朋友可以参考下 nginx可以很方便的配置成反向代理服务器: 1 2 ... 
- nginx服务器中的安全配置
		一.关闭SELinux 安全增强型Linux(SELinux)的是一个Linux内核的功能,它提供支持访问控制的安全政策保护机制. 但是,SELinux带来的附加安全性和使用复杂性上不成比例,性价比不 ... 
- Linux下安装PHP并在nginx服务器中进行配置的详细方法
		先介绍一下使用的环境:centos 7.4, PHP 7.0 , nginx 1.12 Linux系统版本可以通过命令:lsb_release -a 查看. 现在开始步入正题了! 1. 首先查看一下 ... 
- Nginx服务器中的Socket切分,需要的朋友可以参考下
		NGINX发布的1.9.1版本引入了一个新的特性:允许使用SO_REUSEPORT套接字选项,该选项在许多操作系统的新版本中是可用的,包括DragonFly BSD和Linux(内核版本3.9及以后) ... 
- apache服务器中设置目录不可访问
		<Directory "d:/amp/apache/htdocs/images"> Allow from all Options None</Dire ... 
- nginx.conf中配置laravel框架站点
		nginx.conf配置如下: user nginx nginx;worker_processes 4; error_log logs/error.log error; pid logs/nginx. ... 
- Apache服务器中设置端口映射和反向代理的方法
		在/etc/httpd/conf路径下的httpd.conf文件###new add for webui.cong###Include "E:/local/Wamp/bin/apache/A ... 
- upupw  nginx服务器 rewrite设置
		最近开始尝试使用upupw的Nginx套件做开发,感觉还挺不错的,也遇到了一些问题,决定在这里记录一下,同时也希望可以帮助到一些人. 用习惯了Apache,改用Nginx之后会有些不适应,但是咬咬牙就 ... 
- 如何将Vue项目部署到Nginx 服务器中
		https://blog.csdn.net/qq_35366269/article/details/91385689 
随机推荐
- colpick-jQuery颜色选择器使用说明
			一.demo及下载网址:http://www.htmleaf.com/jQuery/Color-Picker/20141108417.html 二.使用效果 三.使用方法 1.引入js和c ... 
- hdu4990 矩阵
			C - Reading comprehension Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ... 
- 01python算法--算法和数据结构是什么鬼?
			我不想直接拷贝google 上面所有对算法的解释.所以我想怎么说就怎么说了,QAQ 1:什么是程序? 解决问题的范式 2:什么是问题? 程序输入与输出之间的联系 3:什么是算法: 算法就是解决问题的思 ... 
- C# asp.net mvc 配置多个route 参数
			mvc 中路由可以自定义 public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { ... 
- Hive 中的分号问题
			1. hive表中有一列值,是以 分号 ; 为分隔符连接存储的 1470047164;1470047628;1470049068;1470048978;1470048922;1470047658;1 ... 
- 【BZOJ-4386】Wycieczki       DP + 矩阵乘法
			4386: [POI2015]Wycieczki Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 197 Solved: 49[Submit][Sta ... 
- 【BZOJ-1040】骑士       树形DP + 环套树 + DFS
			1040: [ZJOI2008]骑士 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3312 Solved: 1269[Submit][Status ... 
- 洛谷P1808 单词分类
			题目描述 Oliver为了学好英语决定苦背单词,但很快他发现要直接记住杂乱无章的单词非常困难,他决定对单词进行分类. 两个单词可以分为一类当且仅当组成这两个单词的各个字母的数量均相等. 例如“AABA ... 
- 如何保持自己 fork 的项目和原始项目同步
			首先先通过 github 的 web 页面 fork 目标的项目 前提是自己已经设置好了git,并且配置了相应的权限 然后使用git clone命令在本地克隆自己 fork 的项目: git clon ... 
- 王高利:Linux__apache,安装,报错解决
			今日编译apache时出错:#./configure --prefix--检查编辑环境时出现:checking for APR... noconfigure: error: APR not found ... 
