2016-08-19 122 views
-1

我已经在我的Windows机器上安装了nginx,并且我做了一个新的laravel安装。我创建了新的路线,但没有其他路线,除了根部工作。我收到一个404错误。Nginx的Windows Laravel路由不工作

错误日志说

“的CreateFile() “C:\ nginx的/ HTML /的Myproj /公/注册” 失败(2: 系统找不到指定的文件),客户端:127.0。 0.1,服务器: 本地主机,请求: “GET /游艇/公/注册HTTP/1.1”,主持人: “localhost” 的”

下面是我的Nginx \的conf \ nginx.conf文件。

#user nobody; 
worker_processes 1; 

#error_log logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 

#pid  logs/nginx.pid; 


events { 
worker_connections 1024; 
} 


http { 
include  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"'; 

#access_log logs/access.log main; 

sendfile  on; 
#tcp_nopush  on; 

#keepalive_timeout 0; 
keepalive_timeout 65; 

#gzip on; 

server { 
    listen  80; 
    server_name localhost; 

    #charset koi8-r; 

    #access_log logs/host.access.log main; 

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

    #error_page 404    /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root 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; 
     fastcgi_param REQUEST_METHOD $request_method; 
     fastcgi_param SCRIPT_FILENAME $document_root$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; 
    #} 
} 


# another virtual host using mix of IP-, name-, and port-based configuration 
# 
#server { 
# listen  8000; 
# listen  somename:8080; 
# server_name somename alias another.alias; 

# location/{ 
#  root html; 
#  index index.html index.htm; 
# } 
#} 


# HTTPS server 
# 
#server { 
# listen  443 ssl; 
# server_name localhost; 

# ssl_certificate  cert.pem; 
# ssl_certificate_key cert.key; 

# ssl_session_cache shared:SSL:1m; 
# ssl_session_timeout 5m; 

# ssl_ciphers HIGH:!aNULL:!MD5; 
# ssl_prefer_server_ciphers on; 

# location/{ 
#  root html; 
#  index index.html index.htm; 
# } 
#} 

} 

请提出任何想法来解决这个问题。

+0

解释“除了根以外的其他路线似乎工作_”的意思是有帮助的。你做了什么;你期望会发生什么;究竟发生了什么,你没有想到?这些是你必须提供给我们的三件事才能理解问题。 – Sherif

+0

编辑我的帖子。请检查。 –

+0

不幸的是,“_it没有工作_”和“_I做了一件未知的事情,导致了通用错误_”并不是有用的度量标准,用于缩小这里可能出现错误的可能列表。您需要检查您的nginx错误日志,并实际查找有关为什么服务器为给定的URI返回404找不到HTTP状态码的更详细的错误信息。否则,提供可能导致这种一般性错误的1001件事情的清单是毫无意义的。 – Sherif

回答

1

在你的nginx配置中,root应该指向Laravel公用文件夹。即

server { 
    listen 80 default_server; 

    root /var/www/laravel/public/; 
    index index.php index.html index.htm; 

    location/{ 
     try_files $uri $uri/ /index.php$is_args$args; 
    } 

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock 
    location ~ \.php$ { 
      try_files $uri /index.php =404; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
    } 

}

3

问题,可能是因为

C:\nginx/html/myproj/public/register 

斜线和反斜线的我想还是在本地使用

php artisan serve 

而不是使用Nginx的。

+0

嘿,非常感谢。这工作!有没有办法配置nginx来避免这种情况。 –

+0

我认为你应该编辑nginx配置文件来解决这个问题。 –