在SSL Nginx上部署Vuejs和Laravel App

时间:2018-12-26 08:34:11

标签: laravel ssl nginx

我有正在工作的Vuejs + Laravel App,它是NGINX代理。我所有的Laravel请求都基于休息,网址为www./app/$。在塞珀尔港口运行良好。但是当我切换到SSL时。我的前端(Vuejs)仍然可以正常工作,但是每当我尝试向后端(laravel)发送发帖请求时,我都会收到[错误] 8#8:* 80 FastCGI在stderr中发送:“主脚本未知”,同时从上游读取响应头。

在443 ssl块中,我将所有其余的api调用转移到phpfpm,但它不起作用。建议在SSL Nginx上部署这些vuejs + laravel的推荐方法。

过去,我曾尝试在ssl服务器块中移动phpfpm。我尝试在fastcgi设置中添加http。完成所有更改后,请执行以下代码:

以下是我的会议文件。

    server {
       listen 81;   # backend  at laravel
        index index.php index.html;
        root /var/www/public;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

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

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

    server { 
         listen 88; # frontend vuejs build app
         index index.html; 
         server_name app.lookahead.com www.app.lookahead.com; 
         error_log /var/log/nginx/error.log; 
         access_log /var/log/nginx/access.log; 
         root /var/www/front; 

         location = /favicon.ico { access_log off; log_not_found off; } 
         location = /robots.txt { access_log off; log_not_found off; }

         return 301 https://$host$request_uri;
     }
     server {

         listen 443;
         server_name app.lookahead.com;

         ssl_certificate           /etc/certs/app.lookahead.com/cert.crt;
         ssl_certificate_key       /etc/certs/app.lookahead.com/cert.key;

        ssl on;
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

        access_log            /var/log/nginx/access.log;

        location / {
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        X-Forwarded-Proto $scheme;
            proxy_pass          http://localhost:8088;
            proxy_read_timeout  90;
            return 301 https://www.app.lookahead.com$request_uri;
           }

       location ^~ /api {
            root /var/www/public;     #backend api at this root
            try_files $uri $uri/ /api/index.php$is_args$args;
            location ~* \.php(/|$) {
            fastcgi_pass  app:9000;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           }
       }
    }



   ##https://www.app.lookahead.com
   server {
       server_name www.app.lookahead.com;
       listen 443;

       ssl_certificate /etc/certs/app.lookahead.com/cert.crt;
       ssl_certificate_key /etc/certs/app.lookahead.com/cert.key;

       ssl on;
       ssl_session_cache  builtin:1000  shared:SSL:10m;
       ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
       ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
       ssl_prefer_server_ciphers on;

       root /var/www/front;        #frontend static vuejs files at this root
       index index.html;

       error_log  /var/log/nginx/error.log;
       access_log /var/log/nginx/access.log;

       location ^~ /api {
           root /var/www/public;   # backend api is at this root
           try_files $uri $uri/ /api/index.php$is_args$args;

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

      # nginx serving frontend
      location / {
        try_files $uri $uri/ @rewrites;
       }


     location @rewrites {
          rewrite ^(.+)$ /index.html last;
       }


    }

0 个答案:

没有答案