增加nginx虚拟主机配置文件(conf.d)
有时候我们安装了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)的更多相关文章
- Nginx 虚拟主机 VirtualHost 配置
Nginx 是一个轻量级高性能的 Web 服务器, 并发处理能力强, 对资源消耗小, 无论是静态服务器还是小网站, Nginx 表现更加出色, 作为 Apache 的补充和替代使用率越来越高. 我在& ...
- Linux(7)- Nginx.conf主配置文件、Nginx虚拟主机/访问日志/限制访问IP/错误页面优化、Nginx反向代理、Nginx负载均衡
一.Nginx.conf主配置文件 Nginx主配置文件conf/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的.一般,每个区块以一对大括号{}来表示开始与结束. 核心模 ...
- 配置Nginx虚拟主机
实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基本环境 1. 安装nginx yum install -y epel-* yum isntall -y nginx vim 2. 建立虚机主 ...
- Apache与Nginx虚拟主机设置(多域名和多端口的区别)
为了方便管理虚拟主机,应该尽量少修改主配置文件http.conf或者nginx.conf,大部分修改变更都在虚拟主机片配置文件httpd- vhost.conf或者vhost.conf中完成,这样有利 ...
- Nginx教程(二) Nginx虚拟主机配置
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- php管理nginx虚拟主机shell脚本
使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考 代码如下 复制代码 #!/usr/bin/php -q& ...
- Nginx虚拟主机配置教程
说明:配置之前先把域名解析到服务器IP地址上 站点1:bbs.osyunwei.com 程序所在目录/data/osyunwei/bbs 站点2:sns.osyunwei.com 程序所在目录/d ...
- nginx虚拟主机的配置
nginx虚拟主机的配置 server { listen ; server_name 127.0.0.1; access_log off; root /var/www/html/; location ...
- Nginx虚拟主机(Virtual Host)配置
虚拟主机(Virtual Host)可以在一台服务器上绑定多个域名,架设多个不同的网站,一般在开发机或者要部署多个小网站的服务器上需要配置虚拟主机.nginx的虚拟主机配置其实也挺简单,为了使得配置文 ...
随机推荐
- percona-xtrabackup系列一:简单使用
1:什么是percona-xtrabackup Percona XtraBackup is an open-source hot backup utility for MySQL -based ser ...
- OpenERP 7中 openerp-server.conf 的解释
服务器启动配置 – 通用项 程序代码: [选择] # Admin password for creating, restoring and backing up databases admin_pas ...
- 【DB2】建造测试数据
建表语句 CREATE TABLE FUND_DAILY_INCOME ( ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTIT ...
- appium架构分析
http://blog.sina.com.cn/s/blog_60c53af50102v3sb.html Appium - automation for mobile apps 一.Appium架 ...
- QTableView中使用Delegate方式来实现对特定列的文本进行换行
问题:由于表格的一个列中,有个别文本过长,默认情况下,QTableView不支持对某列的文本换行,所以需要通过Delegate方式来实现这样的效果 头文件的Delegate #pragma once ...
- 有关于一次windows权限方面的一次学习
由于最近需要使用windows的Local Group Policy的API,重新梳理一些有关windows权限的只是,这样需要理解一些关键概念,这些概念之间的关联联系形成了一张网络图.必须理解才能真 ...
- MessageListActivity has leaked IntentReceiver
1. 在MessagelistActivity中出现has leaked IntentReceiver的异常.异常日志如下. 07-15 08:09:53.211: E/ActivityThread( ...
- 聚集函数查询结果为空, list的size是1, resolve
resultList.removeAll(Collections.singleton(null));
- hihocoder第212周-动态规划
题目链接 import java.util.Scanner; public class Main { long mod = (long) (1e9 + 7); int MAXN = 107; int ...
- mysql 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询
1. 1)MySQL 连接本地数据库,从cmd中进入mysql命令编辑器: root root分别为用户名和密码 mysql -uroot -proot 2)MySQL 连接本地数据库,用户名为“ro ...