大家好
最近买了个域名,租了一台服务器(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
就好了