inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 781 forks source link

[BUG] Inventree production server is running, but I can't connect to it. #2120

Closed 71GA closed 3 years ago

71GA commented 3 years ago

I did all installation steps here and now started the Inventree with a Gunicorn from within my "python virtual environment":

(env) inventree@tekpi-eu:~/src/InvenTree$ /home/inventree/env/bin/gunicorn -c gunicorn.conf.py InvenTree.wsgi

[2021-10-07 11:45:55 +0200] [6252] [INFO] Starting gunicorn 20.1.0
[2021-10-07 11:45:55 +0200] [6252] [INFO] Listening at: http://127.0.0.1:8000 (6252)
[2021-10-07 11:45:55 +0200] [6252] [INFO] Using worker: sync
[2021-10-07 11:45:55 +0200] [6255] [INFO] Booting worker with pid: 6255
[2021-10-07 11:45:55 +0200] [6256] [INFO] Booting worker with pid: 6256
[2021-10-07 11:45:55 +0200] [6257] [INFO] Booting worker with pid: 6257
[2021-10-07 11:45:56 +0200] [6258] [INFO] Booting worker with pid: 6258
[2021-10-07 11:45:56 +0200] [6259] [INFO] Booting worker with pid: 6259
[2021-10-07 11:45:56 +0200] [6260] [INFO] Booting worker with pid: 6260
[2021-10-07 11:45:56 +0200] [6262] [INFO] Booting worker with pid: 6262
[2021-10-07 11:45:56 +0200] [6265] [INFO] Booting worker with pid: 6265
[2021-10-07 11:45:56 +0200] [6270] [INFO] Booting worker with pid: 6270
[2021-10-07 11:45:56 +0200] [6284] [INFO] Booting worker with pid: 6284
[2021-10-07 11:45:56 +0200] [6298] [INFO] Booting worker with pid: 6298
[2021-10-07 11:45:56 +0200] [6306] [INFO] Booting worker with pid: 6306
[2021-10-07 11:45:56 +0200] [6308] [INFO] Booting worker with pid: 6308
[2021-10-07 11:45:56 +0200] [6314] [INFO] Booting worker with pid: 6314
[2021-10-07 11:45:56 +0200] [6321] [INFO] Booting worker with pid: 6321
[2021-10-07 11:45:56 +0200] [6325] [INFO] Booting worker with pid: 6325
[2021-10-07 11:45:56 +0200] [6338] [INFO] Booting worker with pid: 6338
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'
Base currency changed from USD to EUR
Updating exchange rates from https://api.exchangerate.host/latest
Using base currency 'EUR'

I can see that it is using the port 8000:


ss -tuln | grep 8000

Netid       State        Recv-Q       Send-Q             Local Address:Port                Peer Address:Port       
tcp         LISTEN       0            128                    127.0.0.1:8000                     0.0.0.0:*         

But when I visit http://<server's public ip>:8000 with my browser there is nothing there.

My gunicorn.conf.py configuration is as follows:

import multiprocessing

#bind = "0.0.0.0:8000"
bind = "127.0.0.1:8000"

workers = multiprocessing.cpu_count() * 2 + 1

max_requests = 1000
max_requests_jitter = 50

And my config.yaml is:

# Database backend selection - Configure backend database settings
# Ref: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DATABASES
# Specify database parameters below as they appear in the Django docs

# Note: Database configuration options can also be specified from environmental variables,
#       with the prefix INVENTREE_DB_
#       e.g INVENTREE_DB_NAME / INVENTREE_DB_USER / INVENTREE_DB_PASSWORD
database:
  # Uncomment (and edit) one of the database configurations below,
  # or specify database options using environment variables

  # Refer to the django documentation for full list of options

  # --- Available options: ---
  # ENGINE: Database engine. Selection from:
  #         - sqlite3
  #         - mysql
  #         - postgresql
  # NAME: Database name
  # USER: Database username (if required)
  # PASSWORD: Database password (if required)
  # HOST: Database host address (if required)
  # PORT: Database host port (if required)

  # --- Example Configuration - sqlite3 ---
  # ENGINE: sqlite3
  # NAME: '/home/inventree/database.sqlite3'

  # --- Example Configuration - MySQL ---
  #ENGINE: mysql
  #NAME: inventree
  #USER: inventree
  #PASSWORD: inventree_password
  #HOST: 'localhost'
  #PORT: '3306'

  # --- Example Configuration - Postgresql ---
  ENGINE: postgresql
  NAME: inventree_database
  USER: inventree
  PASSWORD: ***********
  HOST: 'localhost'
  #PORT: '5432'

# Select default system language (default is 'en-us')
language: en-us

# System time-zone (default is UTC)
# Reference: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
# Select an option from the "TZ database name" column
# Use the environment variable INVENTREE_TIMEZONE
timezone: UTC

# Base currency code
base_currency: EUR

# List of currencies supported by default.
# Add other currencies here to allow use in InvenTree
currencies:
  - AUD
  - CAD
  - EUR
  - GBP
  - JPY
  - NZD
  - USD

# Email backend configuration
# Ref: https://docs.djangoproject.com/en/dev/topics/email/
# Available options:
# host: Email server host address
# port: Email port
# username: Account username
# password: Account password
# prefix: Email subject prefix
# tls: Enable TLS support
# ssl: Enable SSL support

# Alternatively, these options can all be set using environment variables,
# with the INVENTREE_EMAIL_ prefix:
# e.g. INVENTREE_EMAIL_HOST / INVENTREE_EMAIL_PORT / INVENTREE_EMAIL_USERNAME
# Refer to the InvenTree documentation for more information

email:
  # backend: 'django.core.mail.backends.smtp.EmailBackend'
  host: ''
  port: 25
  username: ''
  password: ''
  sender: ''
  tls: False
  ssl: False

# Set debug to False to run in production mode
# Use the environment variable INVENTREE_DEBUG
#debug: True
debug: False

# Set debug_toolbar to True to enable a debugging toolbar for InvenTree
# Note: This will only be displayed if DEBUG mode is enabled, 
#       and only if InvenTree is accessed from a local IP (127.0.0.1)
debug_toolbar: False

# Configure the system logging level
# Use environment variable INVENTREE_LOG_LEVEL
# Options: DEBUG / INFO / WARNING / ERROR / CRITICAL
log_level: WARNING

# Allowed hosts (see ALLOWED_HOSTS in Django settings documentation)
# A list of strings representing the host/domain names that this Django site can serve.
# Default behaviour is to allow all hosts (THIS IS NOT SECURE!)
allowed_hosts:
  - '*'

# Cross Origin Resource Sharing (CORS) settings (see https://github.com/ottoyiu/django-cors-headers)
# Following parameters are 
cors:
  # CORS_ORIGIN_ALLOW_ALL - If True, the whitelist will not be used and all origins will be accepted.
  allow_all: True

  # CORS_ORIGIN_WHITELIST - A list of origins that are authorized to make cross-site HTTP requests. Defaults to []
  # whitelist:
  # - https://example.com
  # - https://sub.example.com

# MEDIA_ROOT is the local filesystem location for storing uploaded files
# By default, it is stored under /home/inventree/data/media
# Use environment variable INVENTREE_MEDIA_ROOT
media_root: '/home/inventree/data/media'

# STATIC_ROOT is the local filesystem location for storing static files
# By default, it is stored under /home/inventree/data/static
# Use environment variable INVENTREE_STATIC_ROOT
static_root: '/home/inventree/data/static'

# Optional URL schemes to allow in URL fields
# By default, only the following schemes are allowed: ['http', 'https', 'ftp', 'ftps']
# Uncomment the lines below to allow extra schemes
#extra_url_schemes:
#  - mailto
#  - git
#  - ssh

# Permit custom authentication backends
#authentication_backends:
#  - 'django.contrib.auth.backends.ModelBackend'

#  Custom middleware, sometimes needed alongside an authentication backend change.
#middleware:
#  - 'django.middleware.security.SecurityMiddleware'
#  - 'django.contrib.sessions.middleware.SessionMiddleware'
#  - 'django.middleware.locale.LocaleMiddleware'
#  - 'django.middleware.common.CommonMiddleware'
#  - 'django.middleware.csrf.CsrfViewMiddleware'
#  - 'corsheaders.middleware.CorsMiddleware'
#  - 'django.contrib.auth.middleware.AuthenticationMiddleware'
#  - 'django.contrib.messages.middleware.MessageMiddleware'
#  - 'django.middleware.clickjacking.XFrameOptionsMiddleware'
#  - 'InvenTree.middleware.AuthRequiredMiddleware'

What could I possibly be missing? Therefore I amstuck at this official tutorial step.

71GA commented 3 years ago

Ah it wirked if I modified gunicorn.conf.py line:

bind = "127.0.0.1:8000"

like this:

bind = "<server's public ip>:8000"

Weird that later works and former doesn't. It is also weird that at this point, Inventree looks horrible (check the screenshoot). Is it normal to look horible like this at this point in tutorial? I am using version 0.5.0. 20211007_12h07m54s_grim

71GA commented 3 years ago

The above screenshot is not normal behaviour. It shouldn't look this way. I already finished the tutorial, but look hasn't changed.

SchrodingersGat commented 3 years ago

In your config file, you have set debug=False

This means that the /static/ and /media/ files will not be served by the gunicorn web server - see notes here

In a production setup (i.e. debug=False) you will need to serve the media and static files separately.

If you set debug=True you should find that the web interface looks "nice" again (as the static files include the CSS files).

71GA commented 3 years ago

This is exactly what I configured.

matmair commented 3 years ago

@71GA what webserver are you using? Please share the config for the section where inventree is configured?

71GA commented 3 years ago

I fixed it back to debug=True and it works.

matmair commented 3 years ago

I fixed it back to debug=True and it works.

I really think this is / was a issue with the Webserver settings. The gunicorn itself should not be served directly but through a proper proxy or webserver. Maybe take a look if that setup works well.

SchrodingersGat commented 3 years ago

As a starting point, you could have a look at how it is configured in the docker setup. It puts gunicorn behind an nginx proxy which also serves media and static files with the correct permission management.

Setting up Inventree on a bare metal server is a non trivial process!

SchrodingersGat commented 3 years ago

@71GA I'm going to close this issue out, if you still have any question please feel free to re-open it.