Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong App URL #67

Closed
SinoBoeckmann opened this issue Feb 19, 2018 · 15 comments
Closed

Wrong App URL #67

SinoBoeckmann opened this issue Feb 19, 2018 · 15 comments

Comments

@SinoBoeckmann
Copy link

Hey there,
I'm not sure how this can happen but:

I've setup the .env and changed the APP_URL to an normal domain (so no localhost address inside here).
But.. when I run the docker-compose and load the site... all (!) links in the markup are related to to the localhost:/ address (see screenshot below).

My setup is:

  • This docker-container
  • NGINX on the host machine to proxy the localhost address
  • Debian 9, lates docker, latest docker-compose, latest invoiceninja repo-release

So... in theory:

InvoiceNinja-Nginx Container is running at Port 80 and through the docker-compose config file forward it to the host at port 8002 so that I can proxy_pass this via the nginx installation on the host to any domain I want or at least to that one I defined in APP_URL?

I'm just a bit confused... so... maybe someone can explain me why InvoiceNinja is not using the APP_URL instead of the URL provided by InvoiceNinja-Nginx Container

(And yes, I tried this multiple time while deleting everything, removing all docker images etc
)

I added an screenshot to may, clarify it a bit more:
bildschirmfoto 2018-02-19 um 16 01 16

@hillelcoren
Copy link
Member

The APP_URL value is only used in cases where the site is accessed without a browser. ie, when running artisan console commands.

@SinoBoeckmann
Copy link
Author

SinoBoeckmann commented Feb 19, 2018

Okay!
And why is the URL then "hardcoded/ hardlinked" in the markup and not just relative to the domain?

Is there a way to change this? Or at least to change it once to another domain name?

@hillelcoren
Copy link
Member

Sorry, I'm not sure how to change this. It's probably related to using a proxy.

@SinoBoeckmann
Copy link
Author

So... I got it. Somehow.
I needed to add the following lines to my proxy_pass in nginx (host)

proxy_redirect off; proxy_set_header Host $Host

But then I had the problem, that internally in laraval/ symfony the asset-method still get me http links instead of https so unfortunately I needed to change the routes/web.php and add

if (env('APP_ENV') === 'production') { URL::forceSchema('https'); }

on top of this file.
(https://laracasts.com/discuss/channels/laravel/how-i-can-force-all-my-routes-to-be-https-not-http?page=1)

Maybe, it is possible to add this URL::forceSchema('https'); to the repo of invoiceninja if the checkbox (use ssl/tls) is checked in the invoiceninja setup progress!

@hillelcoren
Copy link
Member

Thanks for sharing the solution!

You can add REQUIRE_HTTPS=true to the .env file to require HTTPS

@SinoBoeckmann
Copy link
Author

With REQUIRE_HTTPS=true I'm getting a "too many redirects".

I'm not sure yet what is redirecting so often. I will have a look into this later!

@hillelcoren
Copy link
Member

Maybe this will help:
https://www.invoiceninja.com/forums/topic/ssl-too-many-redirects/#post-8578

Also, you may need to configure the trusted proxies:
http://docs.invoiceninja.com/en/latest/configure.html#using-a-proxy

@SinoBoeckmann
Copy link
Author

@hillelcoren
It is this file:44 that causes the redirects... but I'm not sure why and nor I'm that into Symfony/ Laravel to know where Redirect::secure is come form.

https://github.com/invoiceninja/invoiceninja/blob/3cbf29afad95585e9642775d3d1244460e024a9c/app/Http/Middleware/StartupCheck.php

@SinoBoeckmann
Copy link
Author

I will have a look into that urls... but beside that. Even when I remove this trigger the internal links are not delivered as https as like URL::forceSchema('https'); does!

@hillelcoren
Copy link
Member

Yes, that's the relevant code.

Not sure...

@lalop
Copy link
Member

lalop commented Feb 20, 2018

hey @SinoBoeckmann maybe you should add your proxy as a trusted one https://github.com/invoiceninja/invoiceninja/blob/master/.env.example#L36

@hillelcoren hillelcoren mentioned this issue Feb 21, 2018
@Mzngit
Copy link

Mzngit commented Feb 22, 2018

@SinoBoeckmann For those of us who are newbies, where in the nginx.conf file is your line (prox redirect) line get added?
Also, do you think it has any relevance to the problem in issue #62 relating to Upgrade?
Thanks.

@SinoBoeckmann
Copy link
Author

@Mzngit This is just a "normal" nginx/ "vhost" configuration:
Here is in full grace:

# 1. force the website to be https
server {
	listen 80;
	listen [::]:80;

	server_name domain.name;
	return 301 https://domain.name$uri$is_args$args;
}

# 2. the actual config with the proxy
server {

	listen 443 ssl;
	listen [::]:443 ssl;

	ssl_certificate /etc/letsencrypt/live/domain.name/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/domain.name/privkey.pem;

	server_name domain.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 $scheme;

		# Fix the “It appears that your reverse proxy set up is broken" error.
		proxy_pass		http://127.0.0.1:8858;
		proxy_read_timeout	90;
		#proxy_redirect		http://localhost:8858 https://domain.name;
	}
}

Within this config it is working well.
But there are some other issues with this docker repo here and the Dockerfile!

I will open a pull request later this week with some fixes to the system. :)

@SinoBoeckmann
Copy link
Author

Ah ... and @lalop. I tried the trusted proxy config as you mentioned. But this wasn't working either.
There is something in this case that I'm missing and I will figure it out! :)

@lalop
Copy link
Member

lalop commented Apr 11, 2018

@SinoBoeckmann did you find any explanation ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants