在服务器laravel + nuxt + nginx上部署时,所有路由均返回404

时间:2020-05-21 14:57:45

标签: node.js laravel nginx nuxt.js laravel-6.2

我正在尝试将两者都作为后端上传Laravel 6.2,将Nuxt 2.11作为前端(通用模式)上传到服务器,但是在上载每条路由后都会返回laravel 404,我也在使用nginx反向代理(生产模式)

使用此laravel-nuxt软件包https://github.com/cretueusebiu/laravel-nuxt

上传步骤

1-上传后端文件和文件夹(应用,引导程序,客户端,配置,数据库,路由,存储,供应商,package.json和锁,composer.json和锁)

2-上传前端文件和文件夹(.nuxt,所有内容都包含在我的客户端文件夹中)

3-在我的服务器中,我在nginx.conf onActivityResult()的末尾添加了新行

4-然后在/ etc / nginx / sites-enabled中,我具有带有以下内容的default.conf

include /etc/nginx/sites-enabled/*.conf;

启用我的服务器块并重新启动Nginx ln -s /etc/nginx/sites-available/default.conf / etc / nginx / sites-enabled /

5-设置了pm2服务器的病态,所以我运行pm2 start Laravel-nuxt来开始监听端口3000(午餐nuxt)

这时我访问我的站点,该站点在所有路由上均返回404,无一例外 我也遇到了这个https://github.com/iliyaZelenko/laravel-nuxt/issues/1#issuecomment-491484474 我认为这基本上是我想要做的,甚至尝试过nginx代码但没有成功

我的web.php中有0条路由,所有路由都在api.php中。此外,该项目在localhost dev和prod模式下都可以正常运行,但是当我将其所有404移至服务器时。

1 个答案:

答案 0 :(得分:0)

ssl的正确配置文件 http配置文件

server {
  listen your-server-ip:80;
    server_name example.com;
        return 301 https://www.example.com$request_uri;

}

ssl配置文件

server {
  listen your-server-ip:443 ssl;
    server_name example.com;
        return 301 https://www.example.com$request_uri;

}
server {
    listen your-server-ip:443 ssl;
    server_name www.example.com;
    ssl_certificate /etc/pki/tls/certs/example.com.bundle;
    ssl_certificate_key /etc/pki/tls/private/example.com.key;
      root /home/example/core/public/;
        index index.php;
        access_log /var/log/nginx/example.com.bytes bytes;
       access_log /var/log/nginx/example.com.log combined;
      error_log /var/log/nginx/example.com.error.log error;

location / {

    proxy_set_header                Connection "keep-alive";
    proxy_set_header                Upgrade $http_upgrade;
    proxy_set_header                Connection 'upgrade';
    proxy_http_version              1.1;
    proxy_pass                      https://your-server-ip:3000$uri;
    proxy_intercept_errors          on;# In order to use error_page directive this needs to be on
    error_page                      404 = @php;
}

location @php {
    try_files                       $uri $uri/  /index.php?$query_string;

}

location ~ \.php$ {
   fastcgi_split_path_info         ^(.+\.php)(/.+)$;
    fastcgi_pass                    your-server-ip:9000;
    fastcgi_index                   index.php;
    include                         fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   fastcgi_intercept_errors        off;
    fastcgi_buffer_size             16k;
    fastcgi_buffers                 4 16k;
    fastcgi_connect_timeout         300;
   fastcgi_send_timeout            300;
    fastcgi_read_timeout            300;
}
}

请记住,我的端口是3000,您的端口可能与我们不同

fastcgi_pass也可以加入袜子,但我直接添加了

在我的情况下,

fastcgi_pass端口设置为9000

话虽如此,我们将80和433不带www的重定向到 www ,然后执行反向代理,如果反向代理是404,我们尝试@php和在底部,我们使用php-fpm运行我们的php代码

我几乎花了2个星期学习nginx并编写了不同的配置,直到我想到了这个