Django nginx uwsgi 阿里云配置
uwsgi --ini test_uwsgi.ini
其中uwsgi --ini test_uwsgi.ini:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /root/testd
# Django's wsgi file
module = testd.wsgi #testd是项目名称,而testd.wsgi就是这么规定的写,并没有这个文件
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2
# the socket (use the full path to be safe
socket =127.0.0.1:8081
#http-socket = 127.0.0.1:8081
#http://60.205.211.11 172.17.36.8
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
#http-socket = 172.17.36.8:8081
vacuum = true
然后配置nginx:
在/etc/nginx/conf.d 的defaul.d中添加:
#
# The default server
#
server {
listen 80 default_server;
server_name www.chufangofbx.com;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8081; #必须和uwsgi中的设置一样
}
}
然后 service nginx restart 即可
然后又尝试为了以后 负载均衡考虑,见defult.conf 清空了,转移到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 /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/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 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.
upstream django {
#server unix:///path/to/your/mysite/mysite.sock; # 使用unix套接字
server 127.0.0.1:8081; # 使用TCP端口请注释上一行,并取消本行注释,这里的端口指的是跑uwsgi的端口 #必须和uwsgi中的设置一
}
server {
listen 80 default_server;
server_name www.chufangofbx.com;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass django;
}
}
include /etc/nginx/conf.d/*.conf;
proxy_read_timeout 1800;
proxy_send_timeout 1800;
}
下面是配置https对应修改nginx:
然后在配置小程序服务器的时候,需要使用https而不是http,注意https为ssl加密的协议。
如果是使用的阿里云,需要在阿里云服务中选择ssl服务, 下载nginx对应证书:
在/etc/nginx 目录下面创建cert目录,将ssl证书下载后放置过去
并且修改后缀pem为crt
阿里云控制台=》云计算基础服务=》云服务器ECS=》网络和安全=》安全组,没有安全组的创建一个安全组,有的直接选择相应安全组,点击配置规则=》添加安全组规则(把80端口和443端口添加进安全组,授权对象填0.0.0.0/0)
然后修改nginx配置
|
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ worker_processes auto; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/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 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.
upstream django { #server unix:///path/to/your/mysite/mysite.sock; # ʹÓÃunixÌ×½Ó×Ö server 127.0.0.1:8081; # ʹÓÃTCP¶Ë¿ÚÇë×¢ÊÍÉÏÒ»ÐУ¬²¢È¡Ïû±¾ÐÐ×¢ÊÍ£¬ÕâÀïµÄ¶Ë¿ÚÖ¸µÄÊÇÅÜuwsgiµÄ¶Ë¿Ú #±ØÐëºÍuwsgiÖеÄÉèÖÃÒ» } server { listen 80; listen 443 ssl default_server; ssl on; ssl_certificate /etc/nginx/cert/1861464_www.chufangofbx.com.crt; ssl_certificate_key /etc/nginx/cert/1861464_www.chufangofbx.com.key; #listen 80 default_server; server_name www.chufangofbx.com; root /usr/share/nginx/html; include /etc/nginx/default.d/*.conf;
proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600;
location / { include /etc/nginx/uwsgi_params; uwsgi_pass django; } }
include /etc/nginx/conf.d/*.conf; proxy_read_timeout 1800; proxy_send_timeout 1800; }
|
service nginx restart
浙公网安备 33010602011771号