在WPN-XM中使用Laravel和nginx时出现问题



我安装了WPN-XM,以便将nginx用于Laravel 4.2项目,但只有索引页面可以工作,其他页面(如.../AboutMePage)不能像一样工作

我知道nginx的Laravel配置应该看起来像下面的.conf文件,但我不知道该把它粘贴到哪里。

 # WPN-XM Server Stack 
 # 
 # Nginx Server Setup Example 
 # for an Application based on the Laravel Framework 
 # 
 # Do not forget to add an hosts entry for http://laravel.dev 
 # 
 server 
 { 
     listen       127.0.0.1:80; 
     root         www/laravel/public; 
     # Make site accessible from http://laravel.dev/ 
     server_name laravel.dev; 

     index   index.php index.html; 

     location / { 
         # Request Order: serve request as file, then as directory, 
         # then fall back to displaying a 404. 
         try_files $uri $uri/ /index.php?$query_string; 
     } 

     location ~ .php$ { 
         try_files $uri /index.php =404; 
         fastcgi_split_path_info ^(.+.php)(/.+)$; 
         fastcgi_pass   127.0.0.1:9100; 
         fastcgi_index  index.php; 
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
         include fastcgi_params; 
     } 
 } 

有些事情似乎不正确。

首先,根指令应该使用绝对路径。然后,你想使用http://laravel.dev/访问应用程序,但你读过上面写的内容吗:# Do not forget to add an hosts entry for http://laravel.dev所以如果你的server_name指令设置为http://laravel.dev/您必须将127.0.0.1 laravel.dev添加到主机文件中。最后,nginx日志文件夹为空,因为没有定义error_log。

因此,我建议在nginx.conf 中使用以下服务器块

# WPN-XM Server Stack
#
# Nginx Server Setup Example
# for an Application based on the Laravel Framework
#
# Do not forget to add an hosts entry for http://laravel.dev
#
server {
    listen 127.0.0.1:80;
    root /www/nerds/public; ## Use absolute paths for root directive
    # Make site accessible from http://localhost
    server_name localhost;
    error_log logs/error.log;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root www; ## I let it as default WPN-XM config despite what I said above
    }
    location ~ .php$ {
       try_files $uri /index.php =404;
       fastcgi_split_path_info ^(.+.php)(/.+)$;
       fastcgi_pass 127.0.0.1:9100;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
   }
} 

此配置假定:

  • nerds是你的laravel应用程序文件夹
  • public是您的laravel应用程序的公共目录
  • 您使用访问该应用程序http://localhost/.如果您想更改此项,请不要忘记修改hosts文件和server_name指令
  • 您可以在WPN-XM控制面板中找到nginx日志

最新更新