404 not found after domain change

Hi,

we performed an ERP Next installation on Centos 7 in production mode. When trying to change site1.local to erpnext.ourdomain.com we receive an 404 error.

We added in sites/site1.local/site_config.json
“host_name”: “http://erpnext.ourdomain.com

And we changed in nginx.conf the parts relative to the domain only:

server_names_hash_bucket_size 64;

upstream frappe {
    server 127.0.0.1:8000 fail_timeout=0;
}





server {
        listen 80  default ;
        client_max_body_size 4G;
                    server_name frappe_default_site erpnext.ourdomain.com localhost;
                keepalive_timeout 5;
        sendfile on;
        root /home/erpnext/frappe-bench/sites;

        location /private/ {
            internal;
            try_files /$uri =424;
        }

        location /assets {
            try_files $uri =404;
        }

        location / {
            try_files /site1.local/public/$uri @magic;
        }

        location @magic {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header Host erpnext.ourdomain.com;
                        proxy_set_header X-Use-X-Accel-Redirect True;
            proxy_read_timeout 120;
            proxy_redirect off;
            proxy_pass  http://frappe;
        }
    }

I wanted to add that even localhost or 127.0.0.1 throws a 404 not found error…

Replace

proxy_set_header Host erpnext.ourdomain.com;

to

proxy_set_header X-Frape-Site-Name site1.local;

still 404 with that change

did you reload nginx?

Sorry, should be proxy_set_header X-Frappe-Site-Name site1.local;

OK, now we get it on localhost.

When we log in with any user, we receive the frappe logo but the desk does not load. If we go for example to /user, we receive:

Traceback (innermost last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 23, in render
    data = render_page(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 105, in render_page
    return build(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 114, in build
    return build_method(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/render.py", line 127, in build_page
    context = get_context(path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/context.py", line 36, in get_context
    context = build_context(context)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/website/context.py", line 72, in build_context
    ret = module.get_context(context)
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/templates/pages/user.py", line 14, in get_context
    party = get_lead_or_customer()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 276, in get_lead_or_customer
    "territory": guess_territory(),
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 133, in guess_territory
    get_root_of("Territory")
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/nestedset.py", line 233, in get_root_of
    t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype))[0][0]
 IndexError: tuple index out of range

Something seems wrong with the tree,
@rmehta can you see?

Hi, any news on this? We revised then nginx config and should work.

We are checking the console more in detail, when we log in and go to /addresses, there is a blue loading bar and we get an internal server error:

POST http://erpnext.ourdomain.com/ 500 (INTERNAL SERVER ERROR) jquery.min.js:4l.cors.a.crossDomain.send jquery.min.js:4o.extend.ajax jquery.min.js:4$.extend.call frappe-web.min.js:72fetch_addresses addresses:127(anonymous function) addresses:151j jquery.min.js:2k.fireWith jquery.min.js:2o.extend.ready jquery.min.js:2I jquery.min.js:2
Traceback (innermost last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 49, in application
    response = frappe.handler.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 531, in call
    return fn(*args, **newargs)
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/templates/pages/addresses.py", line 13, in get_addresses
    return get_address_docs()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 288, in get_address_docs
    party = get_lead_or_customer()
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 276, in get_lead_or_customer
    "territory": guess_territory(),
  File "/home/erpnext/frappe-bench/apps/shopping_cart/shopping_cart/shopping_cart/cart.py", line 133, in guess_territory
    get_root_of("Territory")
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/utils/nestedset.py", line 233, in get_root_of
    t2.lft < t1.lft and t2.rgt > t1.rgt) = 0""".format(doctype, doctype))[0][0]
 IndexError: tuple index out of range
 frappe-web.min.js:82$.extend.process_response frappe-web.min.js:82(anonymous function) frappe-web.min.js:74j jquery.min.js:2k.fireWith jquery.min.js:2x jquery.min.js:4(anonymous function)

The nested set indices seem to be broken (?)

You can call this function from your python console.

I am sorry, i never did that, should i access the python console with user erpnext or root? Then with the command python in CentOS i would access the python console right? And then in the console how can i call the function?

Did you add some records directly in the DB

Also some of the older versions had a problem, maybe it is carried over

do

$ bench frappe --ipython
>>> from frappe.utils.nestedset import rebuild_tree
>>> rebuild_tree("Item Group", "parent_item_group")
>>> frappe.db.commit()

Check the fields…