eoinzy
Posts: 10
Joined: Tue Jul 11, 2017 1:08 pm

Help with nginx setup

Sun Aug 11, 2019 11:23 pm

Hi,
I want to have an nginx instance on a pi behind my router, which I can access via Dynamic DNS. i have all the hardware in place, and I installed nginx on the pi already.

I'm having some minor problems. See my config:

Code: Select all

# Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

	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 https;
		proxy_set_header X-Forwarded-Host $remote_addr;
		# First try serve as file, then dir, then throw a 404
		try_files $uri $uri/ =404;
	}
	
	location /router {
		return 302 /router/;
	}

	location /router/ {
		proxy_pass http://192.168.1.1/;
	}

	location /style {
		proxy_pass http://192.168.1.1/style;
	}

	location /image {
		proxy_pass http://192.168.1.1/image;
	}

	location /tv {
		return 302 /tv/;
	}

	location /tv/ {
		proxy_pass http://192.168.1.3/;
	}

	location /vm {
		return 302 /vm/;
	}

	location /vm/ {
		proxy_pass http://192.168.100.1/;
	}

	# pass PHP scripts to FastCGI server
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
		fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	location ~ /\.ht {
		deny all;
	}
}
The main issue is that my /router/ config isn't working as some of the paths aren't being redirected.
For example, there's a link to a path at:

Code: Select all

<script language=javascript type=text/javascript src=/bas_ether.js></script>
But this gives me a 404. I want it to redirect to $IP/router/bas_ether.js, but it looks for the file at $IP/bas_ether.js which is giving the 404. If I manually go to $IP/router/bas_ether.js, it finds the file fine, so its just the redirect that's the issue. There's some gifs and other files as well that aren't redirecting either. Basically anything in the local directory.
So is there something in the config that I can set the base path that will redirect these properly, or do I have to define each one manually?

Also, has anyone hosted websites like this before? What do I ask my web host so they redirect my URL to my dynamic DNS? I want to stop paying a yearly fee for hosting, and just pay for the URLs. I read something about 'A" records but don't understand them. Can I potentially change them and put in my dynamic dns URL and thats it?

Thanks.

Return to “Networking and servers”