nginx下面怎么使用swgger

发布于 2022-06-25 09:34:22

接口文档swgger 怎样打开的,nginx需要进行相关配置吗

查看更多

关注者
0
被浏览
293
2 个回答
hongzai
hongzai 认证专家 2022-06-25
life is coding,外包,远程协助,咨询添加微信:H0nGzA1

默认后端地址127.0.0.1:8000

JY_NIM
JY_NIM 2022-09-07
This guy hasn't written anything yet

在manage.py 同目录下(项目根目录),新建一个目录uwsgi_conf用来放置uwsgi.ini配置文件

[uwsgi]
#地址和端口号
socket=127.0.0.1:9001
#指定运行目录
chdir=/wwwroot/backend/
#载入wsgi-file
wsgi-file=application/wsgi.py
#开启的进程数量
processes=4
#运行线程
threads=2
#允许主进程存在
master=True
#使进程在后台运行,并将日志打到指定的日志文件
logto=/wwwroot/backend/uwsgi_conf/uwsgi.log

uwsgi开机自启

vi /etc/systemd/system/uwsgi.service
[Unit]
Description=Uwsgi Server
After=syslog.target
 
[Service]
KillSignal=SIGQUIT
ExecStart=/usr/bin/uwsgi --ini /wwwroot/backend/uwsgi_conf/uwsgi.ini
Restart=always
Type=notify
NotifyAccess=all
StandardError=syslog
 
[Install]
WantedBy=multi-user.target

将该服务加入到systemd中

systemctl enable /etc/systemd/system/uwsgi.service

配置nginx
vi /etc/nginx/conf.d/default.conf

upstream backend {
   server 127.0.0.1:9001;
}

server {
    listen 443 ssl;
    server_name gbkh.jycollege.cn;
    
    access_log /var/log/nginx/access_web.log;
    error_log /var/log/nginx/error_web.log;
    
    location / {
        root /wwwroot/web;
        index index.html;
    }
}

server {
    listen 80;
    server_name www.sample.com;
    rewrite ^(.*)$ https://$host$1 permanent;
}

server {
    listen 8443 ssl;
    server_name www.sample.com;
    
    access_log /var/log/nginx/access_backend.log;
    error_log /var/log/nginx/error_backend.log;
    
    location / {
        # nginx转发动态请求到uWSGI
        include uwsgi_params;
        uwsgi_connect_timeout 20;
        uwsgi_pass backend;
    }
    
    # 如果写成/static/,nginx无法找到项目静态文件路径
    location /static {
        alias /wwwroot/backend/static;
    }
    
    # 如果写成/media/,nginx无法找到项目媒体文件路径
    location /media {
        alias /wwwroot/backend/media;
    }
}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览