laravel内页不适用于AWS EC2 Nginx

时间:2016-07-19 12:22:36

标签: php apache laravel amazon-web-services

我正在laravel V5.1.11网站上工作,该网站托管在AWS EC2 ubuntungnix服务器上。我成功设置了网站,但我的内页无效。

配置是:

server {
  listen 82;
  server_name www.example.com;
  return 301 https://$server_name$request_uri;
}

server {
    listen 83;
    server_name www.example.com;
    root /home/in4matic/example-website-dev/public;



    location / {
            index index.php;
            try_files $uri $uri/ /index.php?q=$uri&$args;

    }


    location ~* \.php$ {
        fastcgi_index   index.php;
        fastcgi_pass    127.0.0.1:9000;
        include         fastcgi_params;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        #fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_FILENAME    $document_root/index.php;
        #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

    }
}

我该如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

将laravel应用程序从apache移动到nginx不需要很多修改,但由于laravel使用.htaccess文件进行url重写,这在nginx中不起作用,你必须修改nginx配置文件,以便nginx可以重写url。这是我的配置文件的示例:

server {
    listen       80;
    server_name  your-website.com;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000 # Keep this as per your old config;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

}

我一直在为我的所有laravel应用程序使用此配置。

并确保Storage目录具有适当的权限。