liangjda 2015-06-18 04:12 采纳率: 14.3%
浏览 40683

<已解决>nginx配置问题 急急急

大家好
最近买了个域名,租了一台服务器(centos,yum安装 )但再nginx的配置上出了问题
这是我的/etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

     server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

我把虚拟主机的配置放在了/etc/nginx/conf.d/目录下了
文件名:liangzda.com.conf
配置如下:

 server
{
listen 80;
server_name www.liangzda.com;
location /{
proxy_pass http://localhost:8080;
}
}

我安装了tomcat,监听8080端口
打算把访问www.liangzda.com的请求转发给tomcat

一顿配置之后,重启nginx时,提示出错,查看日志文件如下:
[emerg] "server" directive is not allowed here in
/etc/nginx/conf.d/liangzda.com.conf:1

请问应该怎么办?

最后自己发现是自己在conf.d 和 default.conf里面重复放了配置文件
所以出错,我把两个配置文件都删除了,然后自己建了一个文件夹 vhost 然后把配置文件添加到里面 ,再在nginx.conf里面添加include vhost/*.conf
就好了

  • 写回答

3条回答

  • liangjda 2015-06-18 04:13
    关注

    是不是要在hosts里面改东西

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献