这里以配置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服务器中设置多个站点的更多相关文章

  1. Nginx服务器中配置非80端口的端口转发方法详解

    这篇文章主要介绍了Nginx服务器中配置非80端口的端口转发方法详解,文中使用到了Nginx中的proxy_pass配置项,需要的朋友可以参考下 nginx可以很方便的配置成反向代理服务器: 1 2 ...

  2. nginx服务器中的安全配置

    一.关闭SELinux 安全增强型Linux(SELinux)的是一个Linux内核的功能,它提供支持访问控制的安全政策保护机制. 但是,SELinux带来的附加安全性和使用复杂性上不成比例,性价比不 ...

  3. Linux下安装PHP并在nginx服务器中进行配置的详细方法

    先介绍一下使用的环境:centos 7.4, PHP 7.0 , nginx 1.12 Linux系统版本可以通过命令:lsb_release -a 查看. 现在开始步入正题了! 1.  首先查看一下 ...

  4. Nginx服务器中的Socket切分,需要的朋友可以参考下

    NGINX发布的1.9.1版本引入了一个新的特性:允许使用SO_REUSEPORT套接字选项,该选项在许多操作系统的新版本中是可用的,包括DragonFly BSD和Linux(内核版本3.9及以后) ...

  5. apache服务器中设置目录不可访问

    <Directory "d:/amp/apache/htdocs/images">    Allow from all    Options None</Dire ...

  6. nginx.conf中配置laravel框架站点

    nginx.conf配置如下: user nginx nginx;worker_processes 4; error_log logs/error.log error; pid logs/nginx. ...

  7. Apache服务器中设置端口映射和反向代理的方法

    在/etc/httpd/conf路径下的httpd.conf文件###new add for webui.cong###Include "E:/local/Wamp/bin/apache/A ...

  8. upupw nginx服务器 rewrite设置

    最近开始尝试使用upupw的Nginx套件做开发,感觉还挺不错的,也遇到了一些问题,决定在这里记录一下,同时也希望可以帮助到一些人. 用习惯了Apache,改用Nginx之后会有些不适应,但是咬咬牙就 ...

  9. 如何将Vue项目部署到Nginx 服务器中

    https://blog.csdn.net/qq_35366269/article/details/91385689

随机推荐

  1. zabbix 微信报警

    http://blog.csdn.net/wh211212/article/details/52735236 Zabbix可以通过多种方式把告警信息发送到指定人,常用的有邮件,短信报警方式,但是越来越 ...

  2. cocoaPods 的安装和使用

    参考:http://www.360doc.com/content/14/0309/10/11029609_358970353.shtml

  3. 动画: ThemeAnimation(主题动画)

    背水一战 Windows 10 之 动画 PopInThemeAnimation - 控件出现时的动画 PopOutThemeAnimation - 控件消失时的动画 FadeInThemeAnima ...

  4. ASP.net mvc Code First 更新数据库

    code first 数据库迁移步骤如下: 第一步:Add-Migration DataBase_Init 1. Install-Package EntityFramework.zh-Hans –Ve ...

  5. 简单理解dropout

    dropout是CNN(卷积神经网络)中的一个trick,能防止过拟合. 关于dropout的详细内容,还是看论文原文好了: Hinton, G. E., et al. (2012). "I ...

  6. 【BZOJ-1324】Exca王者之剑 最小割

    1324: Exca王者之剑 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 483  Solved: 248[Submit][Status][Disc ...

  7. LINQ语法记录

    static void Main(string[] args) { List<Person> persons = new List<Person>(); persons.Add ...

  8. spoj1811 Longest Common Substring

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  9. JeeSite环境搭建及运行和打包(master20161117)

    涉及的软件: 1.phpStudy(主要用MySql) 2.maven3(用于依赖包,下面我将上传已经下载好所有依赖包的版本,保证运行正常) 具体操作: 0.前言 由于GitHub上的Release版 ...

  10. Deformity ASP/ASPX Webshell、Webshell Hidden Learning

    catalog . Active Server Page(ASP) . ASP.NET . ASP WEBSHELL变形方式 . ASPX WEBSHELL变形方式 . webshell中常见的编码转 ...