有时候我们安装了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. Java对象在虚拟机中的创建、内存分布、访问定位以及死亡判定

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6535156.html  一:虚拟机中对象的创建 1:虚拟机遇到new指令时,在常量池检索是否有对应的符号引用, ...

  2. Jackson序列化日期类型的属性

    @JsonProperty("BankSettlementDate") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = ...

  3. LevelDB和ForestDB简单性能测试(含代码)

    测试环境简单说明 Windows下测试 硬件环境如下: 处理器:Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz 内 存:8GB 硬 盘:希捷 ST1000DM003 操 ...

  4. 修改windows默认的远程连接端口

    打开注册表,找到以下路径项,并修改为你想要的端口,重启服务器即可. HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Serve ...

  5. java开发微信模板消息推送

    发布时间:2018-12-12   技术:springboot+maven   概述 该demo主要涉及微信模板消息推送功能, 详细 代码下载:http://www.demodashi.com/dem ...

  6. java爬虫入门--用jsoup爬取汽车之家的新闻

    概述 使用jsoup来进行网页数据爬取.jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuer ...

  7. Android如何设置TextView的行间距、行高。

         Android系统中TextView默认行间距比较窄,不美观.     我们可以设置每行的行间距,可以通过属性android:lineSpacingExtra或android:lineSpa ...

  8. 如何找到Firefox的收藏夹,就像IE一样,出现在网页的侧面

    firefox有这个插件,安装后就可以 http://addons.mozine.cn/firefox/19/   All-In-OneSidebar ? 概述   All-In-OneSidebar ...

  9. keras的训练引擎:train_array.py和train_generator.py

    keras的Model支持两种模式的训练: 直接传入数组,最终会调用train_array.py中的fit_loop()函数 直接传入生成器,最终会调用train_generator.py中的fit_ ...

  10. IOCP笔记

    IOCP是win32下的异步IO,利用线程池来异步处理IO请求. 这里要分析一下异步调用,跟同步调用不同,异步调用 调用了就马上返回,但是还留下个话:有事情了马上通知我,我会处理滴.恩恩,这很符合我的 ...