如何设置nginx laravel+;vue cli项目

如何设置nginx laravel+;vue cli项目,laravel,ubuntu,nginx,vue.js,Laravel,Ubuntu,Nginx,Vue.js,大家好,我为后台创建laravel,为前端创建Api 在前端,我使用vuejs 如何设置nginx 如果查找路径/管理->进入laravelproject 如果查找路径/api->进入laravel项目 否则只需进入vue项目 这是我现在用的 server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index

大家好,我为后台创建laravel,为前端创建Api

在前端,我使用vuejs

如何设置nginx

  • 如果查找路径/管理->进入laravelproject
  • 如果查找路径/api->进入laravel项目
  • 否则只需进入vue项目
这是我现在用的

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.php  index.htm index.nginx-debian.html;

    server_name localhost;

    location / {
        // Here is working fine run index.html ( vue )
        try_files $uri $uri/ = /index.html;
    }

    location ~ \.php$ {
      // setup php version
      include snippets/fastcgi-php.conf;

      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
   }

    location  /api {
        // I want to go in laravel path here. It's not working 
         root /var/www/html/serverside/public;
         try_files $uri $uri/ /index.php?$query_string;
    }

    location  /admin {
        // I want to go in laravel path here.It's not working 
         root /var/www/html/serverside/public;
         try_files $uri $uri/ /index.php?$query_string;
    }

}
这是我的文件夹结构

/var/www/html/serverside/laravelproject ( in serverside laravel project locate here )
/var/www/html/index.html ( Here is vue js )
*****更新*****

这是我的laravel.conf

server {
    listen 80;
    root /var/www/html/serverside/public;
    index  index.php index.html index.htm;
    server_name  localhost;

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


    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
       fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}
nginx error.log显示
/
etc/nginx/sites enabled/laravel.conf”在/etc/nginx/nginx.conf中失败(40:符号链接级别太多):
62

laravel的最小nginx vhost是这样的,在ubuntu服务器上,该vhost的正确位置是/etc/ngext/sites可用

#laravel.conf
server {
    listen 80;
    root /var/www/html/project_name/public;
    index  index.php index.html index.htm;
    server_name  api.example.com www.api.example.com;

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


    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
       fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

vuejs的最小nginx vhost如下所示,您可以使用pm2的forever在特定端口(如8081)中运行vue js应用程序,以获得代理权限

#vue.conf
server {
  listen 80;
  index index.html;
  server_name example.com www.example.com;

  location / {
      proxy_pass http://localhost:8080;
  }
}
不要忘记在已启用的站点中生成符号链接

# ln -s /etc/nginx/sites-enabled/laravel.conf /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-enabled/vue.conf /etc/nginx/sites-enabled/
# service ntinx -t
# service nginx restart

此外,如果有人出现以下消息错误,您还可以添加ssl配置和更多配置:


nginx.service的作业失败,因为控制进程已退出,错误代码为。我无法运行服务nginx restart/etc/nginx/sites enabled/laravel.conf“失败”(40:符号链接级别太多)

原因是文件链接无法链接同一个文件


示例:ln-s/etc/nginx/sites enabled/laravel.conf/etc/nginx/sites enabled/

它将显示此错误消息

请使用此命令链接文件


/etc/nginx/sites available/{fileName}/etc/nginx/sites enabled/

它不工作,因为
location~\.php$
块继承
根/var/www/html.nginx.service的作业失败,因为控制进程已退出,并显示错误代码。我无法运行服务nginx restart/etc/nginx/sites enabled/laravel.conf“失败(40:符号链接级别过多)请向我发送日志,这不足以解决问题。cat/var/log/nginx/error.log和send me log/etc/nginx/sites enabled/laravel.conf“失败(40:符号链接级别过多)在/etc/nginx/nginx.conf:62I添加了laravel.conf并登录到我的问题错误日志中,错误日志清楚地表明,符号链接级别太多,同一vhost文件在/etc/nginx/sites enabled/fix中多次启用