moktar
9/26/2019 - 11:52 AM

vhost nginx vultr

# Sample LEMP vhost file from VULTR. The default NGINX file is in /var/default-conf/nginx/conf.d

map $http_upgrade $type {
  default "web";
  websocket "ws";
}

server {
	listen 80 default_server;
	server_name yourip;

	root /usr/share/nginx/html/laravelapp/public;
	index index.php index.html;

	# set max upload size
	client_max_body_size 2G;
	fastcgi_buffers 64 4K;

	access_log /var/log/nginx/http_access.log combined;
	error_log /var/log/nginx/http_error.log;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
        }

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

	location @ws {
    		proxy_pass             http://127.0.0.1:6001;
    		proxy_read_timeout     60;
    		proxy_connect_timeout  60;
    		proxy_redirect         off;

    		# Allow the use of websockets
    		proxy_http_version 1.1;
    		proxy_set_header Upgrade $http_upgrade;
    		proxy_set_header Connection 'upgrade';
    		proxy_set_header Host $host;
    		proxy_cache_bypass $http_upgrade;
	}

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

	location = /robots.txt {
		allow all;
		log_not_found off;
		access_log off;
	}

	location ~ \.php$
	{
		try_files      $uri =404;
		fastcgi_pass   127.0.0.1:9000;
		fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
		include        fastcgi_params;
	}

	location ~* \.(htaccess|htpasswd) {
		deny all;
	}

	# set long EXPIRES header on static assets
	location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
		expires 30d;
		access_log off;
	}

}