【问题标题】:Having issues using Laravel and nginx with WPN-XM在 WPN-XM 中使用 Laravel 和 nginx 时遇到问题
【发布时间】:2015-02-16 23:45:24
【问题描述】:

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

【问题讨论】:

  • 你说其他页面不工作。错误是什么?对于您的 nginx 配置,请查看 github.com/WPN-XM/WPN-XM/wiki/Files-and-Folders。它写为 'c:\server\bin\nginx\' 作为 nginx 可执行文件的路径,并使用 'c:\server' 作为默认安装位置进行配置
  • 我有一个 HTTP 404 错误。我得到了 nginx.conf 文件,但不知道是否应该用上面的代码替换它...:/
  • 你的实际配置对 Laravel 来说似乎不错。在 php 位置取消注释 try_files 指令。你不应该需要它。你不能用这个替换 nginx.conf 文件。不要这样做!但是,您可以编辑 nginx.conf(之前制作一个副本)并根据您在此处的配置填充其中的服务器块。你的 nginx.conf 是不是像这里的:github.com/WPN-XM/WPN-XM/blob/master/configs/nginx.conf
  • 说真的,我不知道你在解释什么,我应该用上面的替换 nginx.conf 文件中的服务器块吗?
  • 在您的 nginx.conf 中,您不仅有一个服务器块。你有类似 http { server {} } 的东西。服务器块位于 http 块内。所以编辑 nginx.conf 的第一个 server 块,使它和上面的一样。

标签: php laravel nginx wpn-xm


【解决方案1】:

有一些看起来不正确的事情。

首先你应该为根指令使用绝对路径。 然后,您想使用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 日志

【讨论】:

  • 你好,我终于用这个 Nginx.conf 文件 paste.ee/p/0HvLw 让它工作了。现在我面临另一个可能需要另一个帖子的问题,那就是其他 Laravel 项目如何?我应该为每个项目添加新的根路径及其虚拟主机名还是?
  • 和上面的差不多。请注意,您不使用绝对根路径。对于 Laravel,您应该使用新的根路径和不同的 server_name(或端口,但我不确定是否推荐)添加一个新的服务器块。
猜你喜欢
  • 1970-01-01
  • 2016-04-14
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
  • 2019-09-23
  • 1970-01-01
  • 2015-12-06
相关资源
最近更新 更多