0

Hi I'm create laravel for BackOffice and Api for frontend.

In frontend I use vuejs.

How to setup nginx

  • if find path /admin -> enter to laravelproject
  • if find path /api -> enter to laravel project
  • else just enter in vue project

Here Is what I use now

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

}

Here is my folder structure

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

***** UPDATE *****

Here is my 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 show /etc/nginx/sites-enabled/laravel.conf" failed (40: Too many levels of symbolic links) in /etc/nginx/nginx.conf:62

1
  • It's not working because location ~ \.php$ block inherits root /var/www/html;. Commented Jun 12, 2019 at 8:02

2 Answers 2

2

Minimum nginx vhost for laravel is sth like this,in ubuntu server correct place for this vhost is /etc/ngixt/sites-available.

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

}

Minimum nginx vhost for vuejs is sth like this and you can use forever of pm2 to run your vue js app in perticular port like 8080,8081,... for proxy pass

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

  location / {
      proxy_pass http://localhost:8080;
  }
}

Don't forget to generate symlink in sites enabled

# 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

Additionally you can add ssl configurations and much more,

Sign up to request clarification or add additional context in comments.

5 Comments

Job for nginx.service failed because the control process exited with error code. I cant run service nginx restart /etc/nginx/sites-enabled/laravel.conf" failed (40: Too many levels of symbolic links)
please send me log, this is not sufficient to figure out problem. cat /var/log/nginx/error.log and send me log
/etc/nginx/sites-enabled/laravel.conf" failed (40: Too many levels of symbolic links) in /etc/nginx/nginx.conf:62
I add laravel.conf and log into my question
error log clearly says that Too many levels of symbolic links, same vhost file is enabled multiple times in /etc/nginx/sites-enabled/ fix that issue
0

if someone have this message error:

Job for nginx.service failed because the control process exited with error code. I cant run service nginx restart /etc/nginx/sites-enabled/laravel.conf" failed (40: Too many levels of symbolic links)

The reason because the file link can not link the same file

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

it will show this message error

please link file by using this command

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.