1、uwsgi配置
[root@localhost script]# cat uwsgi.ini
# uwsig使用配置文件启动
[uwsgi]
# 项目目录
chdir=/root/jhr/blog/myblog
# 指定项目的application
module=myblog.wsgi:application
# 指定sock的文件路径
socket=/root/jhr/blog/script/uwsgi.sock
# 进程个数
workers=5
pidfile=/root/jhr/blog/script/uwsgi.pid
# 指定IP端口
http=localhost:8001
# 指定静态文件
#static-map=/static=/root/jhr/blog/myblog/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/root/jhr/blog/script/uwsgi.log
2,uwsgi --ini uwsgi.ini 启动即可
netstat -lntp|grep "uwsgi" 查看端口
在腾讯云上通过yum install uwsgi之后,安装上面方式启动,发现总是出现下面错误
*** no app loaded. going in full dynamic mode ***
-- unavailable modifier requested: 0 --
是因为uwsgi没有办法找到python解释器。
通过pip3 install uwsgi安装一下
3,nginx的配置在/etc/nginx/nginx.conf
4,配置如下:
[root@localhost nginx]# cat 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 root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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.
server {
listen 8002 default_server;
#listen [::]:80 default_server;
server_name 127.0.0.1;
# Load configuration files for the default server block.
large_client_header_buffers 4 16k; # 读取大型客户端请求头的缓冲区的最大数量和大小
client_max_body_size 300m; #设置nginx能处理的最大请求主体大小。
client_body_buffer_size 128k; #请求主体的缓冲区大小。
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
location / {
include uwsgi_params; # 导入一个Nginx模块他是用来和uWSGI进行通讯的
uwsgi_connect_timeout 30; # 设置连接uWSGI超时时间
uwsgi_pass unix:/root/jhr/blog/script/uwsgi.sock; # 指定uwsgi的sock文件所有动态请求就会直接丢给他
}
# 指定静态文件路径
location /static/ {
alias /root/jhr/blog/myblog/static/;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# 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 HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
5,重启即可
nginx -s reload
service nginx restart
6,访问nginx的地址127.0.0.1:8002。动态脚本自动发给uWSGI服务器执行
7,通过/var/log/nginx/目录下的error.og定位错误
8,https的配置,首先要申请一个ssl证书,比如在腾讯云上申请。申请完了下载下来有下面几个目录,其中我们要用的是Nginx目录,这里面有两个文件如下
[root@VM_0_4_centos ssl]# ls -l
total 20
drwxr-xr-x 2 root root 4096 Mar 30 10:16 Apache
drwxr-xr-x 2 root root 4096 Mar 30 10:16 IIS
drwxr-xr-x 2 root root 4096 Mar 30 10:17 Nginx
drwxr-xr-x 2 root root 4096 Mar 30 10:17 Tomcat
-rw-r--r-- 1 root root 1010 Mar 30 10:07 www.jianghaoran.xyz.csr
[root@VM_0_4_centos Nginx]# ls -l
total 8
-rw-r--r-- 1 root root 3697 Mar 30 10:07 1_www.jianghaoran.xyz_bundle.crt
-rw-r--r-- 1 root root 1700 Mar 30 10:07 2_www.jianghaoran.xyz.key
9,接着修改/etc/nginx/nginx.conf 。如下:就是要注意一下https的默认端口是443.
[root@VM_0_4_centos nginx]# cat 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 root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /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.
include /etc/nginx/conf.d/*.conf;
server {
listen 443 default_server;
# listen [::]:80 default_server;
server_name 172.27.0.4;
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
large_client_header_buffers 4 16k; # 读取大型客户端请求头的缓冲区的最大数量和大小
client_max_body_size 300m; #设置nginx能处理的最大请求主体大小。
client_body_buffer_size 128k; #请求主体的缓冲区大小。
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#为一个server开启ssl支持
ssl on;
#为虚拟主机指定pem格式的证书文件
ssl_certificate /root/jhr/ssl/Nginx/1_www.jianghaoran.xyz_bundle.crt;
#为虚拟主机指定私钥文件
ssl_certificate_key /root/jhr/ssl/Nginx/2_www.jianghaoran.xyz.key;
#客户端能够重复使用存储在缓存中的会话参数时间
ssl_session_timeout 5m;
#指定使用的ssl协议
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#指定许可的密码描述
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
ssl_session_cache shared:SSL:50m;
location / {
include uwsgi_params; #导入一个Nginx模块他是用来和uWSGI进行通讯的
uwsgi_connect_timeout 30; #设置连接uWSGI超时时间
uwsgi_pass unix:/root/jhr/uwsgi-script/uwsgi.sock; #指定uwsgi的sock文件所有动态请求就会直接丢给
}
#指定静态文件路径
location /static/{
alias /root/jhr/myblog/static/;
index index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# 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 HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}