nanite icon indicating copy to clipboard operation
nanite copied to clipboard

Nginx Configuration

Open flexchar opened this issue 6 years ago • 3 comments

Hi, it does not work well with Nginx. Here is the working configuration, or else it does NOT see url and ALWAYS return 404.

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

The issue however is that any GET request parameters are invisible to PHP.

Using standard configuration will cause a redirection loop.

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

flexchar avatar Jul 12 '18 08:07 flexchar

Check it

server {
	listen 80;
	server_name mydevsite.dev;
	root /var/www/mydevsite/public;

	index index.php;

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

	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

		# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi.conf;
		fastcgi_intercept_errors on;
	}
}

leotop avatar Sep 04 '18 22:09 leotop

@leotop thank you for sharing. It was a work for a client, that I have no more access to the given environment. Hence unable to test it.

flexchar avatar Sep 06 '18 01:09 flexchar

Doesnt work for me, my nginx.conf

server {
		listen 80;
		server_name ndower.dev;
		root   /srv/http/agc/nanite;
		index index.php;
		location / {
			try_files $uri $uri/ /index.php?$query_string;
		}
		location ~ \.php$ {
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

			# With php5-fpm:
			fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
			fastcgi_index index.php;
			include fastcgi.conf;
			fastcgi_intercept_errors on;
		}
	}

my php

<?php

require_once('Nanite.php');
require_once('functions.php');

get('/', function(){
    echo 'index';
});

get('/about', function(){
    echo '<pre>'.print_r($_SERVER, true).'</pre>';
    echo 'about page';
});

if (!Nanite::$routeProccessed) {
    echo "404";
}

when goto ndower.dev/about, result 404

chokisoklat avatar Mar 04 '20 14:03 chokisoklat