首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx错误!找不到您要查找的页面

nginx错误!找不到您要查找的页面
EN

Stack Overflow用户
提问于 2016-09-23 16:52:28
回答 2查看 13.3K关注 0票数 0

在本教程之后,我将使用Nginx和彪马构建一个使用AWS EC2的测试应用程序。

代码语言:javascript
复制
https://www.sitepoint.com/deploy-your-rails-app-to-aws/

我也能够使用Capistrano成功地部署应用程序。该应用程序也可以在开发中使用。我在开发和生产中使用的是Rails5和Ruby2.3.1。

目前,我有两个页面在开发中,但不在生产中。

在生产环境中使用此URL时

代码语言:javascript
复制
http://ec2-54-226-156-103.compute-1.amazonaws.com/

我得到了

代码语言:javascript
复制
This is the default index.html page that is distributed with nginx on the Amazon Linux AMI. It is located in /usr/share/nginx/html.

而不是我的主页。

当我使用这个URL时

代码语言:javascript
复制
http://ec2-54-226-156-103.compute-1.amazonaws.com/contacts

我得到了

代码语言:javascript
复制
nginx error!
The page you are looking for is not found.
Something has triggered missing webpage on your website. This is the default 404 error page for nginx that is distributed with the Amazon Linux AMI. It is located at /usr/share/nginx/html/404.html
You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.

不知道如何解决这个问题。

以下是我对Nginx的配置文件。

代码语言:javascript
复制
cat /etc/nginx/nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/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;

    index   index.html index.htm;

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

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

        location / {
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
        location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl;
#        listen       [::]:443 ssl;
#        server_name  localhost;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        # It is *strongly* recommended to generate unique DH parameters
#        # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
#        #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#        ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
#        ssl_prefer_server_ciphers on;
#
#        # 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 {
#        }
#    }

}

代码语言:javascript
复制
cat /etc/nginx/sites-available/default

upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/deploy/contactbook/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  listen 80;
  server_name localhost;

  root /home/deploy/contactbook/public;

  try_files $uri/index.html $uri @app;

  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_pass http://app;
  }

  location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

不知道如何修复这些Nginx设置,以使应用程序正常工作,Nginx服务于应用程序的页面?

如果这对您有任何帮助,下面是/home/deploy/contactbook/shared文件夹中的puma配置文件

代码语言:javascript
复制
cat puma.rb

#!/usr/bin/env puma

directory '/home/deploy/contactbook/current'
rackup "/home/deploy/contactbook/current/config.ru"
environment 'production'

pidfile "/home/deploy/contactbook/shared/tmp/pids/puma.pid"
state_path "/home/deploy/contactbook/shared/tmp/pids/puma.state"
stdout_redirect '/home/deploy/contactbook/shared/log/puma_error.log', '/home/deploy/contactbook/shared/log/puma_access.log', true

threads 0,8

bind 'unix:///home/deploy/contactbook/shared/tmp/sockets/puma.sock'

workers 0

prune_bundler

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/home/deploy/contactbook/current/Gemfile"
end
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-23 17:12:12

问题出在sites- server_name localhost; /default中。

我的意思是,nginx将只对Host头匹配"localhost“的请求使用该服务器块。

为了进行测试,您可以将其设置为server_name _;,这是通用的。

最终,您会希望将其设置为您的站点名称,如server_name ec2-54-226-156-103.compute-1.amazonaws.com,但可以等到您有了域名后再进行设置。

票数 3
EN

Stack Overflow用户

发布于 2021-06-14 05:01:32

有东西在你的网站上触发了缺失的网页。这是随Red Hat Enterprise Linux一起分发的nginx的默认404错误页面。它位于/usr/share/nginx/html/404.html

您应该为自己的站点定制这个错误页面,或者编辑nginx配置文件/etc/nginx/nginx.conf中的error_page指令。

有关Red Hat Enterprise Linux的信息,请访问Red Hat,Inc.网站。Red Hat Enterprise Linux的文档可在Red Hat,Inc.网站上找到。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39656619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档