I have an web-service created in BottlePy. Now it is on production.
But only serve to port 80.
I need an HTTPs solution, and I read that NGINX is a good solution.
But is it possible install NGINX without change BottlePy code?
Is it possible serve by port 80 in BottlePy and by port 443 in NGINX?
Some one can help me please?
Thanks
EDIT:
I solve the problem:
/etc/nginx/nginx.conf
:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 443 default_server;
listen [::]:443 default_server;
server_name _;
root /usr/share/nginx/html;
ssl on;
ssl_certificate /xxx.crt;
ssl_certificate_key /xxx.key;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://localhost:80;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Related
I want to upload any size file up to 120Gb via flask on my server.
Currently I get a 502 Bad Gateway error.
Also, sometimes a part of the file is uploaded but never the whole file when the size is above 2Gb.
However, when I upload the file to the Flask debug server, it works (I even tried with a 100Gb file and it worked).
I have changed the nginx configuration very often and tested results from the web, none helped.
The important part of my nginx.conf file
http {
client_max_body_size 200G;
client_body_timeout 3h;
client_body_in_file_only clean;
client_body_buffer_size 16k;
client_body_temp_path /home/nginx/client_body_temp;
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
}
My server nginx configuration
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name cloudster.online www.cloudster.online 85.214.69.4;
ssl on;
ssl_certificate /home/cloudster/Release/data/cert.crt;
ssl_certificate_key /home/cloudster/Release/data/privatekey.key;
proxy_request_buffering off;
proxy_buffering off;
location / {
include proxy_params;
proxy_pass https://unix:/home/cloudster/Release/cloudster.sock;
proxy_max_temp_file_size 100000m;
proxy_temp_path /home/nginx/client_body_temp;
proxy_store off;
proxy_cache off;
}
}
And my service configuartion file
[Unit]
Description=Cloudster executed by Gunicorn
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/cloudster/Release
Environment="PATH=/home/cloudster/Release/venv/bin"
ExecStart=/home/cloudster/Release/venv/bin/gunicorn \
--workers 50 \
--bind unix:cloudster.sock -m 007 \
wsgi:app \
--keyfile data/privatekey.key \
--certfile data/cert.crt \
--worker-class=gevent \
--graceful-timeout=10
[Install]
WantedBy=multi-user.target
I hope someone could help me.
I am currently trying to launch my Django website using Nginx and Gunicorn but my static files are not being found. I am on a Linux AMI not Ubuntu which makes things a bit harder and different because I got Nginx with
sudo amazon-linux-extras install nginx1.12
I was looking at these tutorials
http://www.threebms.com/index.php/2020/07/27/set-up-a-django-app-in-aws-with-gunicorn-nginx/
https://linuxtut.com/en/ce98f7afda7738c8cc1b/
but whenever I launch my website with
gunicorn --bind 0.0.0.0:8000 myappname.wsgi
it always says my static files are not found....
I have already done
python manage.py collectstatic
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
This is my config file found at. sudo vi /etc/nginx/nginx.conf
I don't really know if I should keep the first server part that was there as default but the only part that is not default is the second server but the tutorials say just add a new one to the end
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 8000;
#not real address but same format
server_name 12.18.123.613;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/
{
autoindex on;
alias /home/ec2-user/pydjangoenv/myprojname/static/;
}
location / {
proxy_pass http://12.18.123.613;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# 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;
and the tree goes like this
Django-cloud9 - /home/ec2/user
pydjangoenv
myprojname
blog - this is an app
myprojname
static
users - this is an app
manage.py
requirements.txt
env
I have really been stuck on this for three days, any help is appreciated :-)
EDIT
After adding
urlpatterns =+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
to my urls.py the Django serves the static files, but not when debug is false
the static files don't work, I really have tried everything, please help.
I'm doing build my own django server with nginx and uwsgi.
i almost done but 400 Bad Request always appear...
what am i wrong?
[info] 61794#0: *35 client sent invalid method while reading client request line, client: 127.0.0.1, server: localhost, request: "
QUERY_STRINGREQUEST_METHODGET
CONTENT_TYPECONTENT_LENGTH
REQUEST_URI/ PATH_INFO/"
this is error.log(info)
and this is .conf file
upstream django {
#server localhost:9001;
server unix://~/Desktop/fido_virtual/fido.sock;
}
server {
listen 8999;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location /media {
alias ~/Desktop/fido_virtual/media/;
}
location /static {
alias ~/Desktop/fido_virtual/fidoproject/staticfiles/;
}
location / {
uwsgi_pass django;
include /usr/local/etc/nginx/uwsgi_params;
}
}
this .conf in project folder
upstream django {
#server localhost:9001;
server unix:///Users/junbeomkwak/Desktop/fido_virtual/fido.sock;
}
server {
listen 8999;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location /media {
alias /Users/junbeomkwak/Desktop/fido_virtual/media/;
}
location /static {
alias /Users/junbeomkwak/Desktop/fido_virtual/fidoproject/staticfiles;
}
location / {
uwsgi_pass django;
#include /Users/junbeomkwak/Desktop/fido_virtual/fidoproject/uwsgi_params;
include /usr/local/etc/nginx/uwsgi_params;
}
}
this file is in /usr/local/etc/nginx/site-enabled/.conf
#user nobody;
worker_processes 1;
error_log /var/log/error.log;
#error_log logs/error.log notice;
error_log /var/log/errorngnix.log info;
events {
worker_connections 1024;
}
http {
large_client_header_buffers 4 16k;
include mime.types;
include /usr/local/etc/nginx/sites-enabled/*;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
/ssl
⚡️ /usr/local/etc/nginx cd ..
#user nobody;
worker_processes 1;
error_log /var/log/error.log;
#error_log logs/error.log notice;
error_log /var/log/errorngnix.log info;
events {
worker_connections 1024;
}
http {
large_client_header_buffers 4 16k;
include mime.types;
include /usr/local/etc/nginx/sites-enabled/*;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
and this is /usr/local/etc/nginx/nginx.conf
what is my mistake?... help me
I'm trying to deploy my site using nginx, gunicorn, and django.
When I run gunicorn and load the page at first I was getting a 502 Bad gateway error then I switch the server name to the IP address of my server and now I get a Bad Request 400 error or the domain is unable to be found.
I've been following these steps from Test Driven Development.
I realized last night that I was using my staging server to update my live domain instead of a staging domain. So I created a staging domain as a subdomain of the live domain and created a separate directory for it, then git pulled down the work I had done previously, but it's not working.
My nginx conf file:
server {
listen 80;
server_name my-server-ip-address;
location / {
proxy_set_header Host $host;
proxy_pass http://unix:/tmp/mysitename.socket;
}
location /static {
autoindex on;
root /home/cmac/sites/mysitename/;
}
}
Nginx Error log:
2015/04/11 18:59:16 [error] 18650#0: *494 connect() to
unix:/tmp/mysitename.socket failed (111: Connection refused) while
connecting to upstream
My settings.py:
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = [mysitename]
When I run gunicorn:
[2015-04-11 20:40:39 +0000] [4174] [INFO] Starting gunicorn 19.3.0
[2015-04-11 20:40:39 +0000] [4174] [INFO] Listening at: http://127.0.0.1:8000 (4174)
[2015-04-11 20:40:39 +0000] [4174] [INFO] Using worker: sync
[2015-04-11 20:40:39 +0000] [4177] [INFO] Booting worker with pid: 4177
Things were working before I decided to switch domains.
Edit whole nginx.conf file
user cmac;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
include /etc/nginx/sites-enabled/mysitename;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# location / {
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# root html;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# }
#}
The include file (from /etc/nginx/sites-enabled/mysitename):
server {
listen 127.0.0.1;
server_name my-server-ip-address;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://unix:/tmp/mysitename.socket;
}
location /static {
autoindex on;
root /home/cmac/sites/mysitename/;
}
}
~
~
In mysitename you need to listen on port 80, and server_name as your your staging domain like staging.example.com, also do not use unix sock at the moment, put http://127.0.0.1:8000 in proxy_pass as where your gunicorn serves. Try also comment out the server block in your nginx.conf, it has conflicts with your mysitename.
Also, are you sure user cmac has permissions under your directory/files? normally it runs on www-data.
Hope this helps.
I am trying to deploy my Tornado app with Nginx as proxy. I am trying to run this on Ramnode VPS (512 CVZ) whose configuration is:
512MB RAM
512MB VSwap
2 CPU Core Access
120GB SSD-Cached HDD Space
1Gbps Port
I am not using supervisor as of now and I manually started four instances of my tornado process:
sudo python /home/magneto/pricechase/main.py --port=8000 &
sudo python /home/magneto/pricechase/main.py --port=8001 &
sudo python /home/magneto/pricechase/main.py --port=8002 &
sudo python /home/magneto/pricechase/main.py --port=8003 &
and I can access the site now at pricechase.in:8000 to pricechase.in:8003
I created a new user nginx and gave permissions to my project directory:
sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
sudo chown -R nginx:nginx /home/magneto/pricechase/
Following is the conf file for my project, located at /etc/nginx/sites-enabled/pricechase.in
user nginx;
worker_processes 5;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http{
proxy_next_upstream error;
upstream tornadoes {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;
server {
listen 80;
server_name pricechase.in www.pricechase.in;
location /static/ {
root /home/magneto/pricechase/static;
if ($query_string) {
expires max;
}
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://tornadoes;
}
}
}
When I tried to restart nginx service I was getting following error:
Restarting nginx: nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/pricechase.in:1
nginx: configuration file /etc/nginx/nginx.conf test failed
As the answers indicated here, I commented the following line in /etc/nginx/nginx.conf:
# include /etc/nginx/sites-enabled/*;
Now I can start/restart it however when I type in pricechase.in, its not opening the site. Its not able to access static files also, ex: http://pricechase.in/static/css/tooltipster.css which is located at /home/magneto/pricechase/static/css/tooltipster.css
Following is the contents of /etc/nginx/nginx.conf:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
# include /etc/nginx/sites-enabled/*;
# include /etc/nginx/sites-enabled/pricechase.in;
}
How do I debug this?
Why its not logging any errors? I checked access and error logs (located in /var/log/nginx/)
Any tips/improvements on nginx config files?
If I understand correctly /etc/nginx/nginx.conf is like a base template and all the common config I require for any other hosts should be included in this, right?
If I want to add another domain and serve different tornado instances, I guess I have to add new conf in sites-enabled, however will there be any conflict? for example, I want http://abc.xyz.com to serve static content located in /home/magneto/blog and http://pqrs.com to serve tornado process of ports 8005 to 8008.
A config fragment in sites-enabled should only include the part inside the "http" block; the other parts can only appear at the top-level nginx.conf.