Laravel EC2 Nginx PHP 7 脚本已下载,但未执行

Laravel EC2 Nginx PHP 7 脚本已下载,但未执行

php 脚本被下载到安装了 nginx 的 Amazon ec2 服务器上,而不是被执行。

这是我的 nginx conf 文件:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index index.php index.html index.htm;

    server {
        listen       80;
        server_name  appwarded.com www.appwarded.com;
        root         /var/www/appwarded;
        index index.php index.html index.htm;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        location ~* \.(gif|jpg|jpeg|png|js|css)$ {
        }

        location /app {
            alias /var/www/appwarded/app;

            expires -1;
            add_header Pragma "no-cache";
            add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";

            try_files $uri $uri/ /index.html =404;   
       }

        location ^~ /app/api {
            alias /var/www/appwarded/app/api/public;
            try_files $uri $uri/ @api;
        }   

        location ~ \.php {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location @api {
            rewrite /app/api/(.*)$ /app/api/index.php?/$1 last;
        }

        #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;
        }
    }

}

答案1

我替换了以下块:

location ^~ /app/api {
    alias /var/www/appwarded/app/api/public;
    try_files $uri $uri/ @api;
} 

和:

location ^~ /app/api {
        alias /var/www/appwarded/app/api/public;
        try_files $uri $uri/ @api;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass   127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /path/to/laravel/public/index.php;
        }
}

此项更改解决了该问题。

相关内容