我已经搜索了一段时间来查找这个错误,但我没有在我的配置文件中找到任何令人反感的东西。运行配置测试时,它给出了上述错误(对于添加到虚拟主机默认配置的任何行),这让我很困惑,因为服务器运行良好。我包含了以下文件:
站点可用/默认:
worker_processes 1;
user www-data www-data;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;
upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
# For a TCP configuration:
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
# If no Host match, close the connection to prevent Host spoofing
listen 80 default_server;
return 444;
}
server {
listen 80;
client_max_body_size 4G;
# set the correct host(s) for your site
server_name serverName;
keepalive_timeout 5;
# path for static files
#root /home/ubuntu/appName/static;
location /static {
#root /home/ubuntu/appName/;
alias /home/ubuntu/appName/static/;
}
location / {
proxy_pass http://127.0.0.1:8000;
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}
}
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
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/*;
}
有人能发现我可能做错了什么吗?
答案1
您正在站点级别配置中包含主要级别配置项。
您可以包含在文件中的内容如下sites-enabled
:
upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
# For a TCP configuration:
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
# If no Host match, close the connection to prevent Host spoofing
listen 80 default_server;
return 444;
}
server {
listen 80;
client_max_body_size 4G;
# set the correct host(s) for your site
server_name serverName;
keepalive_timeout 5;
# path for static files
#root /home/ubuntu/appName/static;
location /static {
#root /home/ubuntu/appName/;
alias /home/ubuntu/appName/static/;
}
location / {
proxy_pass http://127.0.0.1:8000;
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://example.com;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /path/to/app/current/public;
}
}