Nginx 总是报告“未找到”

Nginx 总是报告“未找到”

尝试运行 nginx 设置,但每次访问该地址时,都会出现“未找到”的提示,而不是我期望的 laravel 站点。

在我添加 vhost 之前,服务器运行良好,所以我猜想那里有些配置错误。如能帮助发现错误,我将不胜感激。

请注意,网站只能通过 IP 访问,这就是我123.123.123.123为提供填充 IP 的原因server_name

etc/nginx/nginx.conf:

listen 80;

user  nginx;

worker_processes 4;

worker_rlimit_nofile 200000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections 4000;

    use epoll;

    multi_accept on;
}

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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include  /etc/nginx/conf.d/*.conf;
    include  /etc/nginx/sites-enabled/*;
}

etc/nginx/站点可用/mysite.conf:

server {
    server_name  123.123.123.123;
    access_log  /srv/www/mysite/logs/access.log;
    error_log  /srv/www/mysite/logs/error.log;
    root  /srv/www/mysite/public_html/public;
    rewrite_log  on;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log /var/log/nginx/access.log main buffer=16k;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_proxied any;
    #gzip_proxied expired no-cache no-store private auth;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;

    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    sendfile on;

    tcp_nopush on;

    tcp_nodelay on;

    keepalive_timeout 90;

    keepalive_requests 100000;

    reset_timedout_connection on;

    client_body_timeout 30;

    send_timeout 30;

    # Remove trailing slash to please Laravel routing system.
    if (!-d $request_filename) {
        rewrite  ^/(.+)/$ /$1 permanent;
    }

    location / {
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        try_files  $uri =404 $uri/ /index.php?$query_string;
        include  /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        #fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /srv/www/mysite/public_html$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
        deny  all;
    }

    # Set header expirations.
    location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
        expires  365d;
    }
}

答案1

您包括/etc/nginx/sites-enabled/因此,请确保在添加新配置时/etc/nginx/站点可用/后者可用,例如

ln -s /etc/nginx/sites-available/mysite.conf /etc/nginx/sites-enabled/mysite.conf

在您的 mysite.conf 中还添加指令类似

server {
    listen 123.123.123.123;
    server_name  123.123.123.123 "";
    ...
}

“”用于空的 HOST 标头请求,这样就可以了。

更新进一步测试:

为主服务器定义一个 access-default.log 和一个 access-mysite.log,以便您可以看到谁说“未找到”(而不仅仅是错误日志)。

还可以使用 wget 访问每个服务器(您的 IP 服务器和代理服务器)并查看日志。

在主服务器的位置添加“root”指令,并尝试访问非代理文件(如index.html)以查看谁认为负责。

在测试期间,您还可以将所有请求的虚拟服务器标记为 default_server (查看文档)。

答案2

在您的 mysite.conf 中添加一个 listen 指令:

server {
listen 80 default;
server_name  123.123.123.123 "";
...

}

相关内容