有时候我们安装了nginx后发现配置文件只有一个,/etc/nginx/nginx.conf

所有的配置包括虚拟目录也在此文件中配置, 这样当虚拟主机多了管理就有些不方便了,

这是需要我们把配置文件拆分开来,在/etc/nginx/conf.d/ 文件建立对应的域名配置文件,比如 /etc/nginx/conf.d/123.com.conf

怎么配置呢?

只需要在原来文件/etc/nginx/nginx.conf 的http 块下加一句话就可以了:

include /etc/nginx/conf.d/*.conf;

/etc/nginx/nginx.conf完整的代码:

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
include /etc/nginx/conf.d/*.conf;
}

之后就可以把虚拟主机的配置文件写在/etc/nginx/conf.d/目录下了,如123.com.conf

server {
listen ;
server_name .com; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main; location / {
root /var/nginx/html/123.com;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root /var/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root /var/nginx/html/123.com;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

增加nginx虚拟主机配置文件(conf.d)的更多相关文章

  1. Nginx 虚拟主机 VirtualHost 配置

    Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...

  2. Linux(7)- Nginx.conf主配置文件、Nginx虚拟主机/访问日志/限制访问IP/错误页面优化、Nginx反向代理、Nginx负载均衡

    一.Nginx.conf主配置文件 Nginx主配置文件conf/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的.一般,每个区块以一对大括号{}来表示开始与结束. 核心模 ...

  3. 配置Nginx虚拟主机

    实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基本环境 1. 安装nginx yum install -y epel-* yum isntall -y nginx vim 2. 建立虚机主 ...

  4. Apache与Nginx虚拟主机设置(多域名和多端口的区别)

    为了方便管理虚拟主机,应该尽量少修改主配置文件http.conf或者nginx.conf,大部分修改变更都在虚拟主机片配置文件httpd- vhost.conf或者vhost.conf中完成,这样有利 ...

  5. Nginx教程(二) Nginx虚拟主机配置

    Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...

  6. php管理nginx虚拟主机shell脚本

    使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考 代码如下 复制代码 #!/usr/bin/php -q& ...

  7. Nginx虚拟主机配置教程

    说明:配置之前先把域名解析到服务器IP地址上 站点1:bbs.osyunwei.com  程序所在目录/data/osyunwei/bbs 站点2:sns.osyunwei.com  程序所在目录/d ...

  8. nginx虚拟主机的配置

    nginx虚拟主机的配置 server { listen ; server_name 127.0.0.1; access_log off; root /var/www/html/; location ...

  9. Nginx虚拟主机(Virtual Host)配置

    虚拟主机(Virtual Host)可以在一台服务器上绑定多个域名,架设多个不同的网站,一般在开发机或者要部署多个小网站的服务器上需要配置虚拟主机.nginx的虚拟主机配置其实也挺简单,为了使得配置文 ...

随机推荐

  1. debian下配置网络 安装无线网卡驱动 Broadcom BCMXX系列

    解决方案来自于debian官网  https://wiki.debian.org/wl 1.加入源 deb http://http.debian.net/debian/ wheezy main c ...

  2. JDBC编程之预编译SQL与防注入式攻击以及PreparedStatement的使用教程

      转载请注明原文地址: http://www.cnblogs.com/ygj0930/p/5876951.html 在JDBC编程中,常用Statement.PreparedStatement 和  ...

  3. Selenium 的基础框架类

    个人写的一个selenium的base类,应该所有使用selenium的同事都会使用到: package com.hx.baserunner; import static java.io.File.s ...

  4. Window磁盘错误修复chkdsk

    场景: 狗日的垃圾移动磁盘.U盘质量太差劲,会出现磁盘坏道.读写异常~心疼数据.... 命令: 01.Win+R 调出cmd 02.根据移动盘符或磁盘盘符,进行修复 03.执行修复chkdsk /f  ...

  5. Ubuntu16.04下的英文词典Artha

    地址: http://artha.sourceforge.net  http://artha.sourceforge.net/wiki/index.php/Download 在Ubuntu下可以直接安 ...

  6. Intent传递数据全解

    概述 之前的博文也有介绍,查看-->用户界面开发基础 这里单独抽取出来,更加具体的记录一下,事实上主要是API的使用. Intent传递简单数据 能够以直接通过调用Intent的putExtra ...

  7. 【mysql】一条慢查询sql的的分析

    这个是我在jobbole.com 上看到的 先给出数据表table结构 mysql> show create table tt \G *************************** 1. ...

  8. Swift3 隐藏状态栏,修改状态栏颜色

    之前做法: override func viewWillAppear(_ animated: Bool) { UIApplication.shared.isStatusBarHidden = true ...

  9. hihocoder217周 树形DP

    题目链接 一棵树,树中包含TRUE.FALSE.AND.OR四种结点,其中TRUE和FALSE是叶子结点,AND和OR结点的儿子包含多个结点,现在要求执行最少次数的以下操作: 把AND变成OR 把OR ...

  10. wp实例开发精品文章源码推荐(8.20)

    热门源码推荐 WP7快递速查源码http://www.apkbus.com/android-115763-1-1.html WP7仿iphone气泡式短信界面 源码http://www.apkbus. ...