Godaddy DNS to AWS EC2 - nginx

Need help with my web server configuration. I'm using Python Django, Gunicorn, Nginx. DNS Lookup tool shows correct IP. When I go to my domain name it returns Bad Request (400)
#GODADDY RECORDS:
Type Name Value TTL Actions
1. a # 11.222.33.444 600 seconds
2. a www 11.222.33.444 600 seconds
#My SETTINGS.PY FILE:
ALLOWED_HOSTS = ['11.222.33.444']
#NGNIX SETTINGS:
server {
listen 80;
server_name 11.222.33.444 domainname.com www.domainname.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/Portfolio;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/Portfolio/main.sock;
}
}

Related

Nginx configuration for domain name

I have setup my website with nginx configuration and it is working on this adress : http://178.128.44.106/
Howewer when i try to link a domain name to it, I arrive on a NGINX configuration page : http://lawoodtech.fr/
Here is my nginx configuration :
server {
listen 80;
server_name 178.128.44.106 lawoodtech.fr www.lawoodtech.fr;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/djangoadmin/pyapps/woodtech;
}
location /media/ {
root /home/djangoadmin/pyapps/woodtech;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
Any idea on how to fix this ?

Nginx: 403 on static files (port 80 only)

When on a higher port, say 8000, my static files are loaded fine. When I run the server on port 80 (using sudo), I get 403 errors. Any idea why this would be?
My only thought is that its something to do with running as root, the file permissions are all normal, even going -777- doesn't change the error.
# the upstream component nginx needs to connect to
events {
worker_connections 1024;
}
http{
upstream django {
server 127.0.0.1:8001;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
root ~/my/path/;
# the domain name it will serve for
server_name 127.0.0.1;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias _; # your Django project's media files - amend as required
}
location /static/ {
autoindex on;
root /my/path/static/;
}
location ~ \.css {
root /my/path/static/;
}
location ~ \.js {
root /my/path/static/;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include ../uwsgi_params;
}
}
}
You need to add this context to your content directory:
chcon -R -t httpd_sys_content_t /my/path/static
Or you need to disable Selinux.
Edit /etc/sysconfig/selinux file to disable selinux permanently.
setenforce 0 to disable selinux on-the-fly.

How to simulate upstream with Nginx for dynamic subdomains

I would proxy a request like the upstream solution.
server_name ~^(?<subdomain>.+)\.example\.com$;
root /dev/null;
location / {
error_page 502 #nextserver;
resolver 127.0.0.1:53 valid=300s;
proxy_pass "https://$subdomain";
}
location #nextserver {
error_page 502 #error;
resolver 127.0.0.1:53 valid=300s;
proxy_pass "https://$subdomain-blahblah";
}
location #error {
return 502 'Service is not available';
}
As you can see I would check https://$subdomain and if it doesn't exist or it down then checks https://$subdomain-blahblah.
it works fine but the problem happen when the second server is down, then Nginx doesn't provide Service is not available message.
So the scenario is like
check Server A -> down
check Server B -> down
Return custom error
I couldn't use upstream because the name of servers is dynamic.
I would suggest you to solve this problem differently. Check out this sample. It shows how you can approach the problem:
http{
listen 80;
root /path/to/static/files;
upstream_server subdomain1{
server 192.168.1.100:8000;
server 192.168.1.101:8000;
}
upstream_server subdomain2{
server 192.168.1.102:8000;
server 192.168.1.103:8000;
}
location / {
server_name subdomain1.example.com;
proxy_pass http://subdomain1;
include /etc/nginx/proxy_pass;
}
location / {
server_name subdomain2.example.com;
proxy_pass http://subdomain2;
include /etc/nginx/proxy_pass;
}
}

nginx configuration: one location with different server IP

I have the main app running on a server with IP 127.0.0.1 and the domain is http://myexample.com.
I want to add another service to the app with the url http://myexample.com/service.
However, the service is running on another server with IP 127.0.0.2 with port 5000.
How to make nginx configuration work in this situation?
What I have tried is as below:
server {
listen 80;
server_name myexample.com;
location / {
proxy_pass http://127.0.0.1:3002;
client_max_body_size 100m;
}
location /service {
proxy_pass http://127.0.0.2:5000;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}
when I open myexample.com/service, it returns 404 or 500.

Nginx invalid URL prefix

I have a really basic nginx setup which is failing for some reason;
server {
listen 80;
server_name librestock.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/david/StockSearch/stocksearch;
}
location / {
include proxy_params;
proxy_pass unix:/home/david/StockSearch/stocksearch/stocksearch.sock;
}
}
according to everything I've read I'm setting the server name correctly.
when I replace librestock.com with the ip of the server it works.
error:
$ nginx -t
nginx: [emerg] invalid URL prefix in /etc/nginx/sites-enabled/stocksearch:12
nginx: configuration file /etc/nginx/nginx.conf test failed
You need the http:// prefix on your unix: path, as in:
proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;
See
http://nginx.org/en/docs/http/ngx_http_proxy_module.html

Resources