Arquivo da categoria: Nginx

Deploy – How to Install Laravel with an Nginx Web Server on Ubuntu 18.04

Install the Backend Components

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install nginx git php7.3-fpm php7.3-mysql php7.3-mcrypt

Modify the PHP Configuration

sudo nano /etc/php/7.3/fpm/php.ini

Mudar a linha que tem:

;cgi.fix_pathinfo=1

para

cgi.fix_pathinfo=0

sudo service php7.3-fpm restart

Configure Nginx and the Web Root

sudo mkdir -p /var/www/laravel

sudo nano /etc/nginx/sites-available/default

Deve ficar assim:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/laravel/public;
    index index.php index.html index.htm;

    server_name server_domain_or_IP;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Depois sai do arquivo e executa:

sudo service nginx restart

Install Composer and Laravel

cd ~
curl -sS https://getcomposer.org/installer | php

sudo mv composer.phar /usr/local/bin/composer

sudo composer create-project laravel/laravel /var/www/laravel

sudo composer create-project laravel/laravel /var/www/laravel 5.8

sudo chown -R :www-data /var/www/laravel

sudo chmod -R 775 /var/www/laravel/storage
http://server_domain_or_IP

Link de referência: https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04

Share and Enjoy !

0Shares
0 0 0

Nginx.conf

upstream puma {
  server unix:///home/deploy/apps/exemplo/shared/tmp/sockets/exemplo-puma.sock;
}

server {
  listen 80 default_server deferred;
  server_name exemplo.com www.exemplo.com;

  return 301 https://exemplo.com$request_uri;
}

ssl_certificate /etc/letsencrypt/live/exemplo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/exemplo.com/privkey.pem;

server {
  listen 443 ssl;
  server_name exemplo.com;

  root /home/deploy/apps/exemplo/current/public;
  access_log /home/deploy/apps/exemplo/current/log/nginx.access.log;
  error_log /home/deploy/apps/exemplo/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  location /cable {
    proxy_pass http://puma;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

Share and Enjoy !

0Shares
0 0 0

Possíveis configurações no Nginx

events {}

http {

  include mime.types;

  server {

    listen 80;
    server_name 167.99.93.26;

    root /sites/demo;

    # Preferential Prefix match
    location ^~ /Greet2 {
      return 200 'Hello from NGINX "/greet" location.';
    }

    # # Exact match
    # location = /greet {
    #   return 200 'Hello from NGINX "/greet" location - EXACT MATCH.';
    # }

    # # REGEX match - case sensitive
    # location ~ /greet[0-9] {
    #   return 200 'Hello from NGINX "/greet" location - REGEX MATCH.';
    # }

    # REGEX match - case insensitive
    location ~* /greet[0-9] {
      return 200 'Hello from NGINX "/greet" location - REGEX MATCH INSENSITIVE.';
    }
  }
}

Share and Enjoy !

0Shares
0 0 0