Instead of using subdomains I would like to add subfolders like:
burger.domain.com -> domain.com/organization/burger/
is there any way to add /organization/<name:str>/ globaly?
Well, if you have a reverse proxy server like NGINX/Apache, you can update the X-Script-Name. For example in NGINX:
location /organization {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /organization;
}
In that way, django will be served at path /organization(as per configuration of X-Script-Name). You can also checkout this blog for more information regarding deploying django with Apache.
But, if you don't have such reverse proxy server, then you can use FORCE_SCRIPT_NAME. In django settings add the following line:
FORCE_SCRIPT_NAME = '/organization'
Related
I want to deploy django as backend server with nginx.
I use daphne as asgi server due to django channel
location /api {
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;
proxy_pass http://127.0.0.1:10131;
}
as you can see, http://127.0.0.1:10131 is django which should be connected to http://my_domain.com/api
but django can't recognize requested uri.
surely, I set FORCE_SCRIPT_NAME to /api
What should I do further?
please help.
First check whether your daphne service is running on server or not & then try this
server {
listen 80; # can change to 10131
server_name http://my_domain.com;
location /api {
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;
proxy_pass http://127.0.0.1:10131;
}
}
You can change listen port if you want your api accessible to specific port eg. 10131
If you're facing any issues then try to check your daphne logs like this
sudo journalctl -u daphne
and to check your api is running or not run this command
curl http://127.0.0.1:10131/api
you may need to install curl run this to install it
sudo apt install curl
I have added a SSL certificate to my nginx application, everything works fine, but when django paginates for the next url it uses: http:// not https:// How can I change this?
I have solved the issue: Under proxy_pass http://django; SET
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;
Also need to set
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
in setting.py file.
I'm trying to setting up nginx to my PWA app with django backend.
My django backend has some views to pdf reports on /export route.
My PWA app (Vue) runs on /. I'm getting a blank page when access to /export. The blank page is trying to response from PWA, but when I reload with Shift (⇧) it loads the pdf report.
Here is my nginx server config:
server {
server_name awesome.app;
root /home/awesomeapp/pwa;
location /api/ {
include proxy_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://unix:/home/awesomeapp/awesome-backend/awesome.sock;
}
location /export/ {
include proxy_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://unix:/home/awesomeapp/awesome-backend/awesome.sock;
}
location / {
index index.html;
}
}
Any idea how to setting up nginx to allow the access to the pdf report generated by django?
Secondly, django backend also has a dashboard app (no pwa) but nginx does not allows to access it (only with shift(⇧)).
OP here.
I'm using workbox (https://developers.google.com/web/tools/workbox) to simplify service workers management.
Workbox allows exclude url paths in pwa routing (https://developers.google.com/web/tools/workbox/reference-docs/v4/workbox.routing). Black lists solve my problem.
I have created my project in python (Webapp2), but i want to create admin panel in node js and set it in same directory.
I am facing problem how to route node app.js from url
Docker is the best option.
Use docker and create three container (nginx, nodejs, Webapp2).
for nodejs, use port like 8080
for Webapp2, use port like 8000
links nodejs and Webapp2 with ngninx in docker-compose.yml and configure nginx.conf file.
Use nginx.conf like
location /dashboard {
proxy_pass http://nodejs:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://webapp2:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
I would like DRF to use for serialized hyperlinks:
http://<mydomain.com>/api/v1/endpoint
rather than
http://127.0.0.1/api/v1/endpoint
Can this be configured within Django or is it related to my http server configuration (gunicorn+nginx)?
Just set host header for django.
Example for nginx:
location /api/ {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8000;
}
if you are using https, also add :
proxy_set_header X-Forwarded-Proto https;
and everything works fine :)