里云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. 火狐老是弹出下载openh264-win32.zip怎么取消

    OpenH264插件是WebRTC需要调用的一个解码器,从33版本开始内置,默认会自动下载安装和更新,出现这种情况的原因是迅雷或其他下载软件监视浏览器进程,导致火狐无法自动下载响应插件到配置文档中.解 ...

  2. cocopods

    一.什么是CocoaPods 1.为什么需要CocoaPods 在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson.AFNetworking.Reachability等等.使用这些库 ...

  3. Java 常用工具类之基本对象包装类

    为了方便操作基本数据类型值, 将其包装成对象, 在对象中定义了属性和行为, 丰富了该数据的操作. 用于描述该对象的类就称为基本数据类型对象包装类. 基本数据类型对应关系 基本数据类型(8种) 包装类 ...

  4. String trim 坑 对于ascii码为160的去不掉

    大家在使用string   的trim去除空格的时候,要注意一个坑呀,对于ascii码为160的去不掉 import java.util.Arrays; /** * Created by bjchen ...

  5. python multi process multi thread

    muti thread: python threading: https://docs.python.org/2/library/threading.html#thread-objects https ...

  6. 详细介绍Redis的几种数据结构以及使用注意事项(转)

    原文:详细介绍Redis的几种数据结构以及使用注意事项 1. Overview 1.1 资料 <The Little Redis Book>,最好的入门小册子,可以先于一切文档之前看,免费 ...

  7. sql server自动化运维脚本

    数据库运维中盛传一个小段子,我误删除了数据库,改怎么办?有备份还原备份,没有备份就准备简历!听起来有趣但发生在谁身上,谁都笑不起来.接触了很多的客户发现90%客户的运维策略都不是很完善.本篇就分享一些 ...

  8. jQuery Mobile 手动显示ajax加载器

    在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更 ...

  9. python mysqldb 模块学习

    一.安装(环境win7 .python2.7) Python2.x 版本,使用MySQL-python: 安装包:MySQL-python-1.2.5.win32-py2.7.exe(双击安装) 下载 ...

  10. 快速搭建vue脚手架

    https://segmentfault.com/a/1190000011275993