open-eats / OpenEats

:pizza: Self Hosted Recipe Management App :hamburger:
https://open-eats.github.io/
MIT License
670 stars 102 forks source link

Issue accessing from LAN #61

Open smaillot opened 6 years ago

smaillot commented 6 years ago

Hi, I am currently trying to install OpenEats on my computer so that it will be accessible from any computer in the house using the local network.

My installation works fine on localhost and I can login and add recipes as expected. However, when I try to access from my local IP 192.168.x.x OpenEats is showing without any recipe subnails or news and I am not able to login.

I then checked openeats_db_1 logs and I indeed got several:

2018-10-18 9:33:49 27 [Warning] Access denied for user 'root'@'localhost' (using password: NO)

Is there any additional configuration step I forgot for being able to access from LAN ?

RyanNoelk commented 6 years ago

The API needs to be told what domains it is allowed to serve from

Can you try setting the allowed hosts to:

ALLOWED_HOST=localhost, 192.168.x.x, my.domain.com

if that doesn't work can you also try:

ALLOWED_HOST=*

Note: use * isn't recommend if you ever want to open OpenEats to the internet

smaillot commented 6 years ago

I changed this in my env_prod.list but I got the same result even with ALLOWED_HOST=*. I notice an other warning in the log file (that already appears the first time) :

2018-10-18 11:43:07 0 [Note] InnoDB: Using Linux native AIO
2018-10-18 11:43:07 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-10-18 11:43:07 0 [Note] InnoDB: Uses event mutexes
2018-10-18 11:43:07 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-10-18 11:43:07 0 [Note] InnoDB: Number of pools: 1
2018-10-18 11:43:07 0 [Note] InnoDB: Using SSE2 crc32 instructions
2018-10-18 11:43:07 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-10-18 11:43:07 0 [Note] InnoDB: Completed initialization of buffer pool
2018-10-18 11:43:07 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-10-18 11:43:07 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-10-18 11:43:07 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-10-18 11:43:07 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-10-18 11:43:07 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-10-18 11:43:07 0 [Note] InnoDB: 10.3.10 started; log sequence number 11945196; transaction id 10496
2018-10-18 11:43:07 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-10-18 11:43:07 0 [Note] Plugin 'FEEDBACK' is disabled.
2018-10-18 11:43:08 0 [Note] Server socket created on IP: '::'.
2018-10-18 11:43:08 0 [Warning] 'proxies_priv' entry '@% root@b659541d43c4' ignored in --skip-name-resolve mode.
2018-10-18 11:43:08 0 [Note] Reading of all Master_info entries succeded
2018-10-18 11:43:08 0 [Note] Added new Master_info '' to hash table
2018-10-18 11:43:08 0 [Note] mysqld: ready for connections.
Version: '10.3.10-MariaDB-1:10.3.10+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2018-10-18 11:43:08 0 [Note] InnoDB: Buffer pool(s) load completed at 181018 11:43:08
2018-10-18 11:43:36 8 [Warning] Access denied for user 'root'@'localhost' (using password: NO)
2018-10-18 11:44:07 10 [Warning] Access denied for user 'root'@'localhost' (using password: NO)
2018-10-18 11:44:37 25 [Warning] Access denied for user 'root'@'localhost' (using password: NO)

Can this 'proxies_priv' entry '@% root@b659541d43c4' ignored in --skip-name-resolve mode. warning be linked to my issue ?

RyanNoelk commented 6 years ago

Can you provide the error message that the API is sending back when you try and hit if from the local IP? You should be able to get it from your browser console if you are in debug mode or via teh container if not.

I don't think this is an issues with the database or you won't be able to access it via localhost.

I also made a typo in my above statement, can you also try: ALLOWED_HOST=localhost,192.168.x.x,my.domain.com

Note the removed spaces

smaillot commented 6 years ago

Ok I changed back to ALLOWED_HOST=localhost,192.168.x.x.

In my browser console I get this error for client.js:621 when I access to 192.168.x.x:8000:

Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://localhost:8000/api/v1/recipe/mini-browse/?limit=4. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant.[En savoir plus]
Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://localhost:8000/api/v1/news/entry/. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant.[En savoir plus]
Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.

The first error could be translated by Blocking a multiorigin request (Cross-Origin Request) : "Same Origin" politics doesn't allow to access distant ressource located ... Reason : CORS header missing.

RyanNoelk commented 6 years ago

Ahh ok I think I know what is going on. The error your getting is a CORS error.

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin. A web application makes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, and port) than its own origin.

You can download this plugin to confirm: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en

or just change the config to: NODE_URL=192.168.x.x:8000

smaillot commented 6 years ago

You're right, bypassing CORS rules with a plugin or changing NODE_URL solved this issue on my machine. However, when I try to access from another computer I stil have these messages even when enabling the CORS plugin.

RyanNoelk commented 6 years ago

hmm that is quite strange. 2 questions:

smaillot commented 6 years ago

Yes the error is the same when I try on the second computer. The only computer where I can access to the working website is my computer on which OpenEats is running.

RyanNoelk commented 6 years ago

Hmmmmmm that is very strange. So just to recap

This is seeming more like a network issue to me. Is there any more info that you can provide?

smaillot commented 6 years ago

Hum ok i'll try to do this with another network to compare. I don't know what other info I can provide. I installed OpenEats with the docker install guide on a laptop with ubuntu 18 connected to my home wifi router and tried to access from mobile devices on the same network. While connecting to localhost or 192.168.x.x from the laptop running OE all is working but when I try to access to this local IP from any other device on the network, the result is a page that seems to be loading only the frontend, probably the same issue as explained in #60.

RyanNoelk commented 6 years ago

I'll try and replica the setup your going for this weekend and post the results here.

intrinsicaly commented 6 years ago

This issue appears to be the same I was/am having (Issue Running Openeats). I have two setups, one at home and one at work, setup1 has windows host, linux virtualbox with docker install and setup2 has a linux host, linux virtualbox with docker install.

Setup 1 - I managed to get running by adding the ip address of the machine running to the Allowed_Host which is what was suggested above. Happy days Setup 2 - I tried replicating the env_prod.list but it didn't matter what I did I couldn't get full access(*) to the website until out of frustration I changed NODE_API_URL=http://ip address of machine running openeats:8000. Finally happy days However when I returned to setup 1 I suddenly could not access the full site any longer but by changing NODE_API_URL as setup 2 all was good again.

I am not sure if something else will break again but the above seems to have worked for now. Does anyone see any issue in making the above changes? I can currently access the site from any machine on the network

Current Config below

Database config

MYSQL_DATABASE=openeats MYSQL_ROOT_PASSWORD=root

Django config

API_URL=0.0.0.0:8000 API_PORT=8000 DJANGO_SECRET_KEY=sdfsadfas32e98zsdvhhsnz6udvbksjdhfi4galshjfg DJANGO_SETTINGS_MODULE=base.settings DJANGO_DEBUG=False ALLOWED_HOST=localhost,ipaddress HTTP_X_FORWARDED_PROTO=true

Node config

NODE_ENV=production NODE_URL=localhost:8000 NODE_API_URL=http://ipaddress:8000 NODE_LOCALE=en

Hopefully this might someone else. I pressume that the above would not be necessary if running on an outward facing server/host and that the localhost and ipaddress would be replaced by the domain name?

RyanNoelk commented 6 years ago

Sorry I haven't replayed in awhile. My day jab has me pretty busy ATM. Going to have some time in about 2 weeks.

I will create a guide on how to host the app via LAN in a less secure way then one would if it were exposed to the internet. I see there is interest in having OpenEats just for intranet usage.

smaillot commented 6 years ago

Ok thanks, indeed it can be useful for a family to use it on LAN but I think I will also try to make it accessible from outside later. Anyway I'm about to change my setup (network and computer) in few weeks so i'll try again to install OpenEats using your guide. Thanks for your work, I hope I'll have time to contribute to this project.

alexsquared commented 5 years ago

Ryan. Has there been any further development on this. I tried to set it up for the first time on a docker config. I can see my containers running in portainer, and can navigate to the page, but if I try to login, nothing happens.

RyanNoelk commented 5 years ago

So i've dug into this issue and got it working on my local machine so that I can access everything just fine from my phone via wifi.

In any case, I'll be writing up so docs on how to use OpenEats for over LAN. But here is how to get it working.

Follow the docs provided here. With the following changes.

  1. Remove the NODE_API_URL variable for your configuration file (env_prod.list)
  2. Add the internal IP of the server you will be connecting to to the ALLOWED_HOST variable in the configuration file. Not the port, just the IP.
    • For example if your OpenEats instance will be accessed via http://192.168.0.123:1234. Then ALLOWED_HOST=192.168.0.123

Thats it. It should work from there.

Sorry for the long delay.

RyanNoelk commented 5 years ago

I have added this section the the README: https://github.com/open-eats/OpenEats/blob/master/docs/Running_the_App.md#note-for-laninternet-or-static-ip-hosting

I will leave this thread open for a few more weeks unless more issues some up

clanger81 commented 5 years ago

I've attempted every tip above and still can't get an instance of Openeats running on my server via LAN. Continuously get the error '[Warning] Access denied for user 'root'@'localhost' (using password: NO)' despite creating a superuser. Current env_prod.list resembles @intrinsicaly's above with the exception of removing NODE_API_URL as mentioned by @RyanNoelk above. Any help would be appreciated.

kiydev commented 5 years ago

I am trying to do similarly. I am also seeing the access denied errors. I have openeats running, but cannot login (though, can login to '/admin') and see the following error in Chrome when accessing the home page:

client.js:734 Uncaught (in promise) DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
    at u._end (http://192.168.1.4:7000/static/js/main.75933784.js:1:241696)
    at u.end (http://192.168.1.4:7000/static/js/main.75933784.js:1:240998)
    at http://192.168.1.4:7000/static/js/main.75933784.js:1:675276
    at new Promise (<anonymous>)
    at u.r.then (http://192.168.1.4:7000/static/js/main.75933784.js:1:675248)
    at http://192.168.1.4:7000/static/js/main.75933784.js:1:835225
    at http://192.168.1.4:7000/static/js/main.75933784.js:1:545358
    at Object.load (http://192.168.1.4:7000/static/js/main.75933784.js:1:489574)
    at t.value (http://192.168.1.4:7000/static/js/main.75933784.js:1:695465)
    at br (http://192.168.1.4:7000/static/js/main.75933784.js:1:427588)

docker-prod.override.yml:

version: '2.3'
services:
  nginx:
    ports:
      - "7000:80"
    restart: always
  api:
    restart: always
  web:
    restart: on-failure
  db:
    restart: always

env_prod.list:

# Database config
MYSQL_DATABASE=openeats
MYSQL_ROOT_PASSWORD=root

# Django config
API_URL=0.0.0.0:8000
API_PORT=8000
DJANGO_SECRET_KEY=sdfsadfas32e98zsdvhhsnz6udvbksjdhfi4galshjfg
DJANGO_SETTINGS_MODULE=base.settings
DJANGO_DEBUG=False
ALLOWED_HOST=192.168.1.4
HTTP_X_FORWARDED_PROTO=true

# Node config
NODE_ENV=production
NODE_URL=localhost:8080
NODE_API_URL=192.168.1.4:7000
NODE_LOCALE=en
intrinsicaly commented 5 years ago

Hi kiydev, I haven't done a lot with this since, but it appears that you may have a conflict between the ports you are using. Have a look at these and see how you go.

kiydev commented 5 years ago

@intrinsicaly, I don't think there are any port conflicts here.

It appears my issue is caused by not having http:// in the NODE_API_URL. I changed it to: NODE_API_URL=http://192.168.1.4:7000 and everything seems to work well now.

NOTE: I am still seeing those [Warning] Access denied for user 'root'@'localhost' (using password: NO) warnings that @clanger81 is having.

RyanNoelk commented 5 years ago

The [Warning] Access denied for user 'root'@'localhost' (using password: NO) is a red herring. It's not an actual issue. I need to update the db image version but I haven't gotten around to it. The most common issue with local setups is issues with the UI and the API talking to each other.

Given that the IP address for the OpenEats server is 192.168.0.1 and port is 1234.

The first thing to check to is make sure both the API and Ui working independently.

If both the API and UI are working, then check the connection between the two:

If all of the above is true, then you'll need to post a screenshot of your dev tools with the console error message that the UI is giving for me to give you much more info.

Hope this helps :)

clanger81 commented 5 years ago

So I've managed to get it working to some extend after including http:// in NODE_API_URL, homepage and admin page are working, I can login to the admin panel but cannot login to the OpenEats homepage. As far as I can tell, the logs are clean so I'm a little confused at this point.

I think there needs to be a little more clarification on port numbers, I had all the ports the same at 8000 but couldn't get it to work. Once I changed the ports to @kiydev's setup, everything ran but of course I can't log in.

RyanNoelk commented 5 years ago

The logs that the containers give in the terminal should be clean if you can login to the admin site.

If you could post some screen shoots of your network tab in your browser dev tools that would be helpful.

I will look at changing the env file so that it is more clear as to what needs to change as what shouldn't. But the ports that are in the env file don't need to really be changed. They can stay as the default. The only thing that needs to be updated is the 4 envs that are mentioned in the setup guide. (https://github.com/open-eats/OpenEats/blob/master/docs/Running_the_App.md#configure-the-environment-file). The you should be connecting to the UI from http://192.168.0.1:1234 and the admin page from http://192.168.0.1:1234/admin