2017-02-24 191 views
0

下面是我的配置文件和我的網站的網址是https://www.fossbytes.tk/login/,我想訪問,但我無法訪問nginx中的子頁面。在Apache我使用全部覆蓋所有;命令訪問所有頁面和子頁面,但在nginx的情況下它不起作用。Nginx返回404在子頁面上找不到錯誤

如何解決下面的配置文件和訪問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" 

回答

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; 
# } 
#} 
0

看起來你有位置錯誤嘗試使用

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

無法正常工作仍然會出現相同的錯誤 –

+0

您是否重新加載服務器?什麼訪問日誌說? – bobomam

+0

服務器重新啓動但不工作 –