I need some help deploying react js + django + CentOS + SSL.
Here's what I have:
react-ui/src/config/constant.js
BACKEND_SERVER = "http://mysite.mydomain.xxx:8000/api/";
react-ui/package.json
"start": "HTTPS=true react-scripts start",
"build": "HTTPS=true react-scripts build",
react-ui/.env
HTTPS=true
yarn start
django
I know some of these are high risk entries, but I am working on getting this functional.
ALLOWED_HOSTS = [ '*' ]
CORS_ALLOW_ALL_ORIGINS=True
# Load the default ones
CORS_ALLOWED_ORIGINS = ["https://localhost:3000", "https://mysite.mydomain.xxx:3000"]
CSRF_TRUSTED_ORIGINS = ["https://localhost:3000", "https://mysite.mydomain.xxx:3000"]
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SESSION_EXPIRE_AT_BROWSER_CLOSE=True
run django
python manage.py runserver 0.0.0.0:8000
/etc/nginx/nginx.conf
upstream mysite_server {
server unix:/home/myuser/mysite/django-api/mysite.sock fail_timeout=0;
}
server {
listen 80;
server_name mysite.mydomain.xxx;
#location = /favicon.ico { access_log off; log_not_found off; }
#location /static/ {
# root /home/myuser/mysite/django-api;
#}
#location / {
# proxy_set_header Host $http_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://unix:/home/myuser/mysite/django-api/mysite.sock;
# }
return 301 https://mysite.mydomain.xxx$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name mysite.mydomain.xxx;
root /usr/share/nginx/html;
ssl_certificate "/etc/pki/tls/private/star-yyy-xxx.bag";
ssl_certificate_key "/etc/pki/tls/private/star-yyy-xxx.bag";
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https; # <-
proxy_set_header Host $http_host;
proxy_redirect off;
}
#
error_page 404 /404.html;
location = /40x.html {
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
sudo service nginx start
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=myuser
Group=myusergroup
WorkingDirectory=/home/myuser/mysite/django-api
ExecStart=/home/myuser/.local/bin/gunicorn --workers 3 --bind unix:/home/myuser/mysite/django-api/mysite.sock core.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl start gunicorn
sudo service httpd stop
What am I missing? Why doesn't this work?