阿里云centOS7.4 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2

里云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

原文地址:https://www.cnblogs.com/yuzhould/p/9064149.html

时间: 2024-10-10 09:28:02

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

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

想检查一个配置文件是否正确,-c 指定之后发现有报错,如下: [[email protected]2:~# nginx -t -c /etc/nginx/conf.d/default.conf nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 nginx: configuration file /etc/nginx/conf.d/default.conf t

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

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

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

在配置nginx 虚拟机时,执行 sudo /usr/sbin/nginx -t 报下面的错误: nginx: [emerg] "root" directive is duplicate in /etc/nginx/server/blogs.conf:7 nginx: configuration file /etc/nginx/nginx.conf test failed 错误原因是:在配置文件时,访问路径设置了两个,重复配置webroot路径导致,去掉一个就可以了. server {

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

问题环境: 阿里云centos7.4.1708 问题描述:成功配置,启动成功,外网访问不了 解决方案: 经过查阅文档,去阿里云后台查看,原来是新购的服务器都加入和实例安全组. (OMG)立即去配置.加入你的80端口,立即就能开启了. 正常默认的是这3个规则 这里在入[方向下]点击任一条规则后面的克隆,在协议类型里面选择HTTP(80)或者想要添加的协议,其他不动,点击确定 在用ip请求 原文地址:https://www.cnblogs.com/SongG-blogs/p/8819516.html

阿里云Centos7使用yum安装MySQL5.6.24的正确姿势

阿里云Centos7使用yum安装MySQL5.6.24 阿里云Centos7使用yum安装MySQL5.6.24 前言:由于某些不可抗力,我要在自己的阿里云服务器上搭建hadoop+hive+mysql+tomcat环境,下为mysql的安装记录 →_→大家都知道,centos自带的repo是不会自动更新每个软件的最新版本,所以无法通过yum方式安装MySQL的高级版本.所以,即使我使劲用yum -y install mysql mysql-server mysql-devel,也是没有人会鸟

nginx: [emerg] "fastcgi_pass" directive is duplicate in /etc/nginx/sites-enabled/default:57

/************************************************************************************************ * nginx: [emerg] "fastcgi_pass" directive is duplicate in /etc/nginx/sites-enabled/default:57 * 说明: * VPS安装Ubuntu 16.04,调一下Nginx的PHP Server. * * 20

阿里云CentOS7搭建Apache+PHP+MySQL环境,注意php加载mysql的方法

阿里云CentOS7搭建Apache+PHP+MySQL环境 投稿:mrr 字体:[增加 减小] 类型:转载 时间:2017-03-24我要评论 最近要搭建一个阿里云的LMAP环境,选了CentOS7来做搭建.下面通过本文给大家分享阿里云CentOS7搭建Apache+PHP+MySQL环境,感兴趣的朋友一起看看吧 最近要搭建一个阿里云的LMAP环境,选了CentOS7来做搭建. 1.Apache Centos7默认已经安装httpd服务,只是没有启动. 如果你需要全新安装,可以yum inst

阿里云Centos7搭建Samba

2018.11.13第二章前缀不述,略过阿里云控制台等信息(这些都是中文的,稍微瞄一眼都能知道,比较坑的就是规则了,第一个Smaba搭好之后由于没建好规则就一直访问不了,当然这问题百度一下就知道了)自己总结了一下可以搭建的服务,如下列表,然后由易到难开始搭建(主要简单的都会,难的还没开始学).言归正传,开始第一个服务的搭建--Samba.由于本人的学习都是看视频和资料自学,所以老实说很不规范和系统,搭建环境的第一步是干什么?--百度搜阿里云Centos7搭建Samba直接出来一堆,然后再自己归纳

nginx:[emerg]unknown directive "ssl"

nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:102 到解压的nginx目录下 ./configure --with-http_ssl_module 当执行上面语句,出现./configure: error: SSL modules require the OpenSSL library. 用 yum -y install openssl openssl-devel 再执行./con