Skip to content

Instantly share code, notes, and snippets.

@huzaifa-a
Last active November 6, 2022 18:18
Show Gist options
  • Save huzaifa-a/2650ec619aa14590f35c9912c8798a19 to your computer and use it in GitHub Desktop.
Save huzaifa-a/2650ec619aa14590f35c9912c8798a19 to your computer and use it in GitHub Desktop.
Nginx localdevelopment with laravel
sudo apt-get install nginx

Enable php and update root path in default config file

sudo apt-get install nginx
cd /etc/nginx/sites-available
server {
	listen 80 default_server;
	listen [::]:80 default_server;


	root /home/huzaifa/www;

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

	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php8.0-fpm.sock;
	}

	location ~ /\.ht {
		deny all;
	}
}

.test virtual host for laravel project

sudo gedit /etc/hosts

# add host line at the end
127.0.0.1	pwa.developmentpreview.test

Create new Nginx confix file


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

	server_name pwa.developmentpreview.test;

	root /home/huzaifa/www/websitemonitor-ocean/public;

	add_header X-Frame-Options "SAMEORIGIN";
    	add_header X-XSS-Protection "1; mode=block";
    	add_header X-Content-Type-Options "nosniff";

    	index index.html index.htm index.php;

    	charset utf-8;

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

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

    error_page 404 /index.php;

  location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

Restart Nginx

sudo systemctl restart nginx.service 

Nuxt js configrations

server {
    root /home/huzaifa/www/websitemonitor-ocean/public;
    index index.html;
    server_name pwa.developmentpreview.test;

    location /auth/google {
    	root /home/huzaifa/www/websitemonitor-ocean/public;

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

    location /callback/google {
    	root /home/huzaifa/www/websitemonitor-ocean/public;

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


    location /api {
    	root /home/huzaifa/www/websitemonitor-ocean/public;

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



    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_redirect          off;
        proxy_buffering         on;
        proxy_cache_valid       200 1d;
        proxy_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;

        proxy_pass              http://localhost:3000;

        proxy_read_timeout      1m;
        proxy_connect_timeout   1m;
    }


    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment