Monthly Archive: July 2020

Laravel with Nginx config file example

Just for my reference.

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

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

Redirect ip website using Nginx configuration

Want to prevent other visitor can view the ip website (e.g xxx.xxx.xxx.xxx/test_website), because it just for local test.

Solution:

add below script into server{}

set $allow 0;
if ($remote_addr ~ "your allowed ip 1") { set $allow 1;}
if ($remote_addr ~ "your allowed ip 2") { set $allow 1;}
if ($remote_addr ~ "your allowed ip 3") { set $allow 1;}

if ($allow ~ 0) {
	rewrite ^ https://www.google.com;
}