【问题标题】:Nginx returns 404 not found error on sub pagesNginx 在子页面上返回 404 not found 错误
【发布时间】:2017-07-15 04:38:00
【问题描述】:

下面是我的配置文件,我的网站网址是https://www.fossbytes.tk/login/,我想访问但我无法访问 nginx 中的子页面。在 apache 中,我使用 all override all;命令访问所有页面和子页面,但在 nginx 的情况下它不起作用。

如何修复以下配置文件并在没有 htaccess 的情况下访问 nginx 中的所有子页面

server {
ssl_dhparam  /etc/nginx/ssl/dhparam.pem;
ssl_certificate /etc/nginx/ssl/fossbytes.tk.crt;
ssl_certificate_key /etc/nginx/ssl/fossbytes.tk.key;
location ~ /.well-known {
                allow all;
        }

        server_name fossbytes.tk www.fossbytes.tk;
        return 301 https://$server_name$request_uri;
   }

server {

        # SSL configuration


    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
         include snippets/ssl-fossbytes.tk.conf;
         include snippets/ssl-params.conf;
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php login.php index.html index.htm index.nginx-debian.html;

autoindex off;

        server_name fossbyte.tk;

        location / {
                # First attempt to serve request as file, then
access_log off; # do not log access to static files
    expires max;
}

                include snippets/fastcgi-php.conf;
        #
 #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

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

        }

location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
        }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

我的错误日志

2017/02/24 11:42:38 [error] 32739#32739: *1 open() "/var/www/html/affiliate/fonts/fontawesome-webfont.woff2" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/fonts/fontawesome-webfont.woff2?v=4.5.0 HTTP/1.1", host: "fossbytes.tk", referrer: "https://fossbytes.tk/affiliate/css/font-awesome.min.css"
2017/02/24 11:42:38 [error] 32739#32739: *8 open() "/var/www/html/affiliate/js/angular-aria.min.js.map" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/js/angular-aria.min.js.map HTTP/1.1", host: "fossbytes.tk"
2017/02/24 11:42:38 [error] 32739#32739: *11 open() "/var/www/html/affiliate/js/angular-route.min.js.map" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/js/angular-route.min.js.map HTTP/1.1", host: "fossbytes.tk"
2017/02/24 11:42:38 [error] 32739#32739: *7 open() "/var/www/html/affiliate/js/angular-animate.min.js.map" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/js/angular-animate.min.js.map HTTP/1.1", host: "fossbytes.tk"
2017/02/24 11:42:39 [error] 32739#32739: *9 open() "/var/www/html/affiliate/js/angular-messages.min.js.map" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/js/angular-messages.min.js.map HTTP/1.1", host: "fossbytes.tk"
2017/02/24 11:42:39 [error] 32739#32739: *5 open() "/var/www/html/affiliate/fonts/fontawesome-webfont.woff2" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /affiliate/fonts/fontawesome-webfont.woff2?v=4.5.0 HTTP/2.0", host: "www.fossbytes.tk", referrer: "https://www.fossbytes.tk/affiliate/css/font-awesome.min.css"
2017/02/24 11:42:43 [error] 32739#32739: *5 open() "/var/www/html/favicon.ico" failed (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /favicon.ico HTTP/2.0", host: "www.fossbytes.tk", referrer: "https://www.fossbytes.tk/"
2017/02/24 11:45:14 [error] 32739#32739: *5 "/var/www/html/login/index.php" is not found (2: No such file or directory), client: 120.60.31.120, server: fossbyte.tk, request: "GET /login/ HTTP/2.0", host: "www.fossbytes.tk"

【问题讨论】:

    标签: apache ubuntu nginx configuration server


    【解决方案1】:

    您的位置似乎有错误尝试使用

    location / {
    try_files $uri $uri/ =404;
    }
    

    【讨论】:

    • 你在重新加载服务器吗?访问日志说什么?
    • 我正在使用 all override all; in .htaccess in apache server
    • 'sudo nginx -t' 是什么意思
    • 但这是 nginx 而不是 apache 的配置。 Nginx 根本不使用 .htaccess
    • root@OM:/etc/nginx# sudo nginx -t nginx: 配置文件/etc/nginx/nginx.conf 语法没问题 nginx: 配置文件/etc/nginx/nginx.conf 测试成功了
    【解决方案2】:

    这就是我为nginx 配置文件的方式,它对我来说非常好。

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##
    
    # Default server configuration
    #
    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
    
        server_name 128.199.143.50;
    
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php;
    
        }
    
    
        location /affiliate_services {
    try_files $uri $uri /affiliate_services/index.php;
    rewrite ^/affiliate_services/(.*)$ /affiliate_services/index.php?url=$1 last;
    
    }
    
    location /affiliate {
    try_files $uri $uri /affiliate/index.php;
    #rewrite ^/cshelpdesk/(.*)$ /cshelpdesk/index.html last;
     }
    
    location /api {
    #try_files $uri $uri /api/flipkart_api.php;
    #rewrite ^/api/(.*)$ /api/flipkart_api.php last;
     }
    
     # Expire rules for static content
    
    # cache.appcache, your document html and data
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
      expires -1;
      # access_log logs/static.log; # I don't usually include a static log
    }
    
    # Feed
    location ~* \.(?:rss|atom)$ {
      expires 1h;
      add_header Cache-Control "public";
    }
    
    # Media: images, icons, video, audio, HTC
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
    }
    
    # CSS and Javascript
    location ~* \.(?:css|js)$ {
      expires 1y;
      access_log off;
      add_header Cache-Control "public";
    }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
        #
        #   # With php7.0-cgi alone:
        #   fastcgi_pass 127.0.0.1:9000;
        #   # With php7.0-fpm:
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
    
         # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny all;
        }
    }
    
    
    # Virtual Host configuration for example.com
    #
    # You can move that to a different file under sites-available/ and symlink that
    # to sites-enabled/ to enable it.
    #
    #server {
    #   listen 80;
    #   listen [::]:80;
    #
    #   server_name example.com;
    #
    #   root /var/www/example.com;
    #   index index.html;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}
    

    【讨论】:

      猜你喜欢
      • 2015-05-31
      • 2014-08-01
      • 1970-01-01
      • 2021-03-31
      • 2021-07-25
      • 1970-01-01
      • 2012-08-16
      • 2019-12-09
      • 2018-12-16
      相关资源
      最近更新 更多