使用Laravel和nginx与WPN-XM有问题

时间:2015-02-16 23:45:25

标签: php laravel nginx wpn-xm

我安装了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; 
     } 
 } 

1 个答案:

答案 0 :(得分:1)

有些事情似乎不正确。

首先,您应该使用root指令的绝对路径。 然后,您想要使用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;
   }
} 

此配置假定:

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