I have a Django app running a site, abc.com using nginx on the frontend.
The URL: http://abc.com/products/widget shows the widget product page. I would like to also have the URL http://getwidget.com point at the same product page. How can I configure nginx to do this?
My current nginx config is like this:
server {
listen 80;
server_name abc.com;
location / {
client_max_body_size 10M;
proxy_pass http://127.0.0.1:8200;
}
location /static/
{
root /home/projects/abc/static;
}
}
Add another server {} something like this:
server{
listen 80;
server_name getwidget.com;
root /path/to/webroot;
}
This new server can point to your project as well as the old one. If you hardcoded some urls in your project you will need to correct this.
Related
I have my domain on GoDaddy and my hosting setup in DigitalOcean. So after I setup my basic django project, I used a droplet to deploy the code to an IP address. When I run this command, my project was running at my [IP_ADDRESS]:8000:
gunicorn -w 2 -b 0.0.0.0:8000 --chdir /home/USER_NAME/projectdir/test_project test_project.wsgi
Then, I put the three digital ocean nameservers in GoDaddy. I also modified the settings.py file by using the ALLOWED_HOSTS variables:
ALLOWED_HOSTS = ['IP_ADDRESS', 'www.DOMAIN_NAME', 'DOMAIN_NAME']
My Nginx configuration looks something like this:
server {
listen 8000;
listen 80;
server_name IP_ADDRESS DOMAIN_NAME www.DOMAIN_NAME;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/USER_NAME/projectdir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
But still, I get 'This Site can't be reached'. I also checked that the nameservers have been updated by using https://lookup.icann.org/en. So I don't know where the problem lies. If you need any additional information let me know. Thank you
I have the following nginx config: I am running two servers Nodejs(port:3000) and django(port:8000)
http {
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:3000; <-- NODEJS APP
}
location /api {
proxy_pass http://127.0.0.1:8000; <-- DJANGO APP
}
}
}
I want to access Django at {domain_name}/api and anything other than that will be fetched from Nodejs
I want to access all the /admin and whatever urls mentioned in the Django at /api
Is there any way to do that.
I know i can add /api infornt of all the urls in the urls.py.
But this can be dynamic. So I dont want to disturb the urls.
I have a single application in django hosted on AWS. But, in these days, I turned It into multi-tenancy, using django-tenant-schemas. Locally, It runs normally. I can create my tenants and access them on my local django server. However, I'm not getting to run on AWS.
My .conf file for NGINX looks like this:
upstream django {
server unix:///home/ubuntu/folder_my_projct/mysite.sock; # for a file s$
}
# configuration of the server
server {
listen 80; address or $
server_name ssh *.example.com.br;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /media {
alias /home/ubuntu/folder_my_projct/media; # your Django project's$
}
location /static {
alias /home/ubuntu/folder_my_projct/static; # your Django project's$
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/ubuntu/folder_my_projct/uwsgi_params; # the uwsgi$
}
}
I did pull for my project that runs on AWS, everything worked in my Virtual Machine (makemigrations and migrate_schemas). However, when I try to access the subdomain, It doesn't work. My only change to access the subdomains was in the file above, pasting the * before the dot: * .example.com.br. I tried using regex, but it didn't work as too (server_name ~^(?<subdomain>.+)\.example\.com\.br $;). I do really appreciate if someone tells me what I'm doing wrong, or if I need to do anything else.
Change this line server_name ssh *.example.com.br;
by
server_name ssh.example.com.br *.example.com.br;
or server_name *.example.com.br;
For each subdomain you'll need to create a configuration, depending what you want to access
server {
server_name ssh.example.com.br;
...
}
server {
server_name blabla.example.com.br;
...
}
server {
server_name *.example.com.br;
...
}
I've created a django application, deployed it on DigitalOcean, and everything works and looks well when using website via IP address. Now I've bought a domain and want to use it for my application, but don't know what to do. First of all I've added my domain name to ALLOWED_HOSTS in settings.py, then DigitalOcean's DNS servers added to site where I bought domain. But app doesn't work via domain name yet. Here are my codes:
settings.py:
ALLOWED_HOSTS = ['64.225.1.249', 'forexample.az']
nginx:
/etc/nginx/sites-available/myproject
server {
listen 80;
server_name my_ip_address (not domain, maybe here I should write domain name ?);
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/my/_username//myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/my/_username/myproject.sock;
}
}
I have a problem understanding how to run my Django app with Nginx (server is Ubuntu).
So, I have a site which allows for user accounts, and it currently has a problem, where both "www" and non-"www" URLs load. This is problematic, because logging-in to one, will not reflect to the other. Besides that, it's also confusing. I want to keep the non-"www" variant.
I followed the instructions here on how to do it using Ngnix:
https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-ubuntu-14-04
And it worked when I tried to load the domain. But when I started the Django app, it stopped working.
I'm really confused on how to get it working, is there some way of running my django app through Nginx?
Thanks!
EDIT: I've included the server config thing (I think)
default
server {
server_name www.nilly.com;
return 301 $scheme://nilly.com$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}