里云centOS7.4配置多个站点遇到的问题
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2
这个错误好尴尬,
费了几个小时去解决,小白呀没办法

先贴下/etc/nginx/nginx.conf的内容

worker_processes 1;
events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; include /etc/nginx/vhost/*.conf; server {
listen 80;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/vhost/*.conf;
}
}

vhost/mayifa.conf内容

server
{
listen 80;
server_name localhost;
root /data/www/mayifanx;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

  

就这个配置好好的,systemctl restart nginx ,依照命令使用systemctl status nginx.service
检测为什么为老是报错
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2

所以nginx.conf中server节点的 include /etc/nginx/vhost/*.conf; 应该被删掉

正确的/etc/nginx/nginx.conf配置如下

worker_processes 1;
events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; include /etc/nginx/vhost/*.conf; server {
listen 80;
server_name _;
root /usr/share/nginx/html;
}
}

systemctl restart nginx

终于正常了。

可以使用 nginx -t -c /etc/nginx/nginx.conf  这个检测配置是否正常,今天才明白nginx.conf配置是把你指定include配置一起包含的,类似C++中的include

阿里云centOS7.4 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2的更多相关文章

  1. nginx检查报错:nginx: [emerg] "server" directive is not allowed here in

    想检查一个配置文件是否正确,-c 指定之后发现有报错,如下: [root@op-2:~# nginx -t -c /etc/nginx/conf.d/default.conf nginx: [emer ...

  2. nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx.conf:36

    nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx ...

  3. nginx: [emerg] "proxy_cache_path" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:43

    1.它只能使用于http{  }部分,把proxy_cache_path放置于http部分即可解决此问题.注意图示的上下文

  4. 阿里云centos7服务器nginx配置及常见问题解答

    前言: 本文参考了jackyzm的博客:https://www.cnblogs.com/jackyzm/p/9600738.html,进行了内容的更新,并请注意这里适用的版本是centos7的版本.并 ...

  5. 配置 nginx server 出现nginx: [emerg] "root" directive is duplicate in /etc/nginx/server/blogs.conf:7

    在配置nginx 虚拟机时,执行 sudo /usr/sbin/nginx -t 报下面的错误: nginx: [emerg] nginx: configuration file /etc/nginx ...

  6. 阿里云centos7搭建php+nginx环境

    阿里云Centos搭建lnmp(php7.1+nginx+mysql5.7) https://jingyan.baidu.com/article/215817f7a10bfb1eda14238b.ht ...

  7. 阿里云CentOS7.3服务器通过Docker安装Nginx

    前言 小编环境: 阿里云CentOS7.3服务器 docker 下面分享一次小编在自己的阿里云CentOS7.3服务器上使用Docker来安装Nginx的一次全过程 温馨小提示: 如果只是希望单纯使用 ...

  8. 阿里云centos7成功安装和启动nginx,但是外网访问不了的解决方案

    问题环境: 阿里云centos7.4.1708 问题描述:成功配置,启动成功,外网访问不了 解决方案: 经过查阅文档,去阿里云后台查看,原来是新购的服务器都加入和实例安全组. (OMG)立即去配置.加 ...

  9. 阿里云CentOS7部署ASP.NET Core

    本文主要介绍了阿里云CentOS7下如何成功的发布ASP.Core应用并使用nginx进行代理, 并对所踩的坑加以记录; 环境.工具.准备工作 服务器:阿里云64位CentOS 7.4.1708版本; ...

随机推荐

  1. Office word中去掉首页的页眉

    1.首先将光标位置移动到第二页的开始,然后点击页面布局命令. 2.页面布局里面找到分隔符,找到下一页的分隔符.(分页符分页) 3.双击第二页的页眉,打开页眉编辑菜单.将连接到前一条页眉的命令去掉. 4 ...

  2. 第4章 x86反汇编速成班

    4.1 抽象层次 硬件<微指令<机器码<低级语言<高级语言<解释型语言 4.2 逆向工程 4.3 x86体系结构 冯-诺依曼体系结构 中央处理器(CPU): 负责执行代码 ...

  3. Design Pattern - 访问者模式

    访问者模式 访问者模式(Visitor), 表示一个作用于某对象结构中的各元素的操作.它使你可以在不改变各元素的类的前提下定义作用于这些元素的新操作. 这个模式相对比较复杂, 而又很少能被用上, 拿G ...

  4. 洛谷 [BJOI2012]最多的方案

    洛谷 这题是旁边同学介绍的,听他说记忆化搜索可以过... 不过我还是老老实实的想\(dp\)吧- 先看看数据范围,\(n\leq10^{18}\)相当于\(n \leq fib[86]\). 以前打\ ...

  5. Scrapy(爬虫)基本运行机制

    Scrapy(爬虫)基本运行机制

  6. phalcon—— PHP基础知识(一)

    一.变量和常量 1.1.变量名(标示符) 1)变量:$开头标志 2)变量名:能够由字母.数字,_ 3者组成,不能用数字开头 3)标识符是区分大写和小写的.但函数名不区分大写和小写. 4)变量名称能够与 ...

  7. Java中Collections和Collection的区别

    java.util.Collection Collection 层次结构 中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 collection 允许 ...

  8. 品牌管理之万变与不变——From 品牌管理培训

  9. mysql 建立表之间关系 一对一 练习1

    创建db5数据库 create database db5 charset=utf8; use db5; 例一:一个用户只有一个博客 用户表: id name 1 mike 2 alex 3 jack ...

  10. java反射基础知识(一)

    一.反射 反射:JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为 ...