我有一个nginxconfiguration设置,并在/etc/nginx/sites-available/default-staging 。 今天我已经尝试添加另一个基于这种configuration的邮件营销应用程序。
在运行service nginx restart命令失败后,我在网上查了一下,发现nginx -c /etc/nginx/sites-available/sendy-newsletter -t应该突出显示任何sytax错误,它给出了以下结果。
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/sendy-newsletter:1 nginx: configuration file /etc/nginx/sites-available/sendy-newsletter test failed
有两件事让我困惑,首先,我不明白为什么服务器块将不被允许,在网上检查后,似乎这可能会导致如果sites-enabledconfiguration文件不包括在我的nginx.conf的hhtp块nginx.conf ,但他们是:
user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 2048; multi_accept on; use epoll; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; # gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #}
其次,当我从sites-available和sites-enabled文件夹中删除了sendy-newsletterconfiguration,正如所料,我可以成功重启nginx服务器,但奇怪的是,当我运行nginx -c /etc/nginx/sites-available/default-staging -t我得到了和以前一样的错误信息,但是服务器工作正常!
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-available/default-staging:1 nginx: configuration file /etc/nginx/sites-available/default-staging test failed
这里是我在/etc/nginx/sites-available/sendy-newsletter的完整configuration,它是sym链接的,并且在sites-enabled了sites-enabled
server { listen 80; #listen [::]:80; server_name newsletter.example.com; autoindex off; index index.php index.html; root /var/www/sendy-newsletter/public; # access_log /var/www/sendy-newsletter/logs/access.log; # error_log /var/www/sendy-newsletter/error.log; # Don't allow search engines to index any add_header X-Robots-Tag "noindex, noarchive"; location / { try_files $uri $uri/ $uri.php?$args; } location /l/ { rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last; } location /t/ { rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last; } location /w/ { rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last; } location /unsubscribe/ { rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last; } location /subscribe/ { rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 last; } location ~ \.php$ { # --PHP5-FPM CONFIG START (keep fastcgi_param HTTPS OFF)-- #fastcgi_pass unix:/var/run/php5-fpm.sock; ##fastcgi_param HTTPS $fastcgi_https; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # --PHP5-FPM CONFIG START-- # --HHVM CONFIG START-- fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #include fastcgi_params; try_files $uri $uri/ @handler; # --HHVM CONFIG END-- include fastcgi_params; } location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; log_not_found off; expires 30d; } }
UPDATE
我检查了我的nginx错误日志,并在尝试重新启动nginx后收到此消息。
2015/11/18 13:09:44 [emerg] 21899#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/11/18 13:09:44 [emerg] 21899#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/11/18 13:09:44 [emerg] 21899#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/11/18 13:09:44 [emerg] 21899#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/11/18 13:09:44 [emerg] 21899#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/11/18 13:09:44 [emerg] 21899#0: still could not bind()
这也是运行的结果:
$ sudo nginx -c /etc/nginx/nginx.conf -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
另外我试图删除我不使用的configuration文件后运行语法testing
$ sudo rm default-staging $ sudo rm ../sites-enabled/default-staging $ sudo nginx -c / etc / nginx / sites-available / sendy-newsletter -t nginx:[emerg]“server”指令是不允许的/ etc / nginx / sites-available / sendy:1 nginx:configuration文件/ etc / nginx / sites-available / sendy test failed
当然你得到一个错误:) nginx -c应该检查你的整个web服务器configuration,而不仅仅是服务器块。 只要在主要的conf文件上运行它,你就会看到。 它会自动考虑任何链接的服务器指令。
这就是为什么您应该在进行检查之前删除您从站点启用的目录中不使用的(指向链接的)指令。 你可以随时链接回去。
我是这样的涂料,忘了我有另一个应用程序上运行的清漆,所以80端口正在使用。 这是问题,错误日志指出我在正确的方向,而Nginx-C只是混淆了我。