Nginx在子页面上返回404未找到错误

时间:2017-02-24 11:05:46

标签: apache ubuntu nginx configuration server

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

如何修复以下配置文件并访问nginx中的所有子页面而不使用htaccess

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"

2 个答案:

答案 0 :(得分:0)

看起来您在位置上有错误尝试使用

hidden

答案 1 :(得分:0)

这就是我为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;
#   }
#}