EADST

阿里云部署个人博客Django+uWSGI+Nginx

自己的博客之前就写好了,只不过一直没有上线,趁着最新有一篇论文的结果需要展示, 就抽时间把博客部署好。在部署过程中查了很多资料,踩过许多坑,现在总结一下步骤, 汇集一下靠谱的指导教程。

阿里云服务器购买

我本来想在AW和GCP之间蹭免费的服务器,但是看到阿里云的服务器并不贵,就一下买了三年的。

阿里云服务器领券购买

我购买的是双核,2G,3M带宽,40G云盘的ECS, 领完券后是779元三年。Ubuntu 16.04 64bit作为操作系统。

服务器初始化

因为在配置中需要修改路径和文件,所以我就安装了一个Ubuntu桌面。 主要安装步骤是参考这个链接

阿里云服务器ECS Ubuntu16.04-64-bit学习之一:配置桌面

只不过我通过阿里云自己的VNC控制服务器。

之后安装Anaconda 5.0.1 (Python 3.6.3)

Anaconda3-5.0.1-Linux-x86_64.sh

执行命令:bash Anaconda3-5.0.1-Linux-x86_64.sh

安装路径为/home/anaconda3,确保anaconda的python 3.6.3为默认python.

参考链接

Ubuntu安装anaconda 介绍、安装、配置

然后通过pip install安装相应的libraries.

博客配置

因为我的博客代码里包含容量比较大的文件,所以没法用GitHub,就压缩文件夹用Google Drive上传下来。 博客文件夹被放在 /home/www/blog/

此外,上线前需要将setting.py文件修改好。因为有了Ubuntu桌面,所以我用 sudo gedit file 来修改文件。

ALLOWED_HOSTS = ['*']
DEBUG = False
BASE_DIR = "/home/www/blog/static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

同步Django静态文件拷贝到设置的statics目录

python manage.py collectstatic

之后运行python manage.py runserver 在Ubuntu自带的火狐浏览器中打开网页 127.0.0.1:8000

uWSGI配置

uWSGI配置主要是参考这篇文章。

Liunx之Ubuntu下Django+uWSGI+nginx部署

这个是我配置的uwsgi.ini文件

[uwsgi]

chdir=/home/www/blog/

module=MyBlog.wsgi:application

workers=5
pidfile=/home/www/blog/script/uwsgi.pid
# http=172.17.171.6:8000 #上线时替换成 socket=172.17.171.6:8000
socket=172.17.171.6:8000 # 阿里云私网IP

static-map=/static=/home/www/blog/static

uid=root
gid=root

master=true

vacuum=true

thunder-lock=true

enable-threads=true

harakiri=30

post-buffering=4096

daemonize=/home/www/blog/script/uwsgi.log

注意,这里填的http和socket是阿里云私有IP, 后面的8000端口需要去阿里云服务器的安全组里添加。

nginx配置

nginx配置也踩了许多坑,主要是之前服务器装过apache2,所以就算nginx可以正常运行,但是也显示不了这个页面。

后来把nginx重新安装后,在etc/nginx/conf.d/下创建blog.conf文件。 这是我的blog.conf

server {  
        listen 80;
        server_name 39.107.202.98; # 阿里云公网IP,或者是域名
        access_log  /home/www/blog/script/access.log;
        error_log  /home/www/blog/script/error.log;
        charset  utf-8;
        gzip on;
        gzip_types text/plain application/x-javascript text/css text/javascript application/json text/json image/jpeg image/gif image/png application/octet-stream;
        error_page  404           /404.html;
        error_page   500 502 503 504  /50x.html;
        location / {
            include uwsgi_params;
            uwsgi_connect_timeout 30;
            uwsgi_pass 172.17.171.6:8000;  # 与阿里云私网IP一致
        }
        location /static/ {
            alias  /home/www/blog/static/;
            index  index.html index.htm;
        }
}

具体配置可以参考这个链接

网站部署:Django+Nginx+Uwsgi+阿里云

之后启动nginx,就可以通过外网IP 39.107.202.98 查看博客了~

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
关于博主 公式 transformers v2ray Python llama.cpp GIT Gemma Web 阿里云 CUDA ResNet-50 CTC Excel Crawler printf GPT4 Miniforge 图形思考法 Website Quantize Search 顶会 Ptyhon 净利润 Distillation diffusers GoogLeNet CEIR Rebuttal Knowledge mmap FP64 Nginx Algorithm Bipartite SQLite News Data YOLO Review LeetCode torchinfo GPTQ 多线程 scipy VPN QWEN Markdown 音频 TTS Zip API ModelScope Clash Food FP8 CC LLAMA tar SQL Pandas MD5 IndexTTS2 Video BTC Land DeepSeek 继承 icon OpenCV Linux NLP Animate SPIE Interview FP32 Translation Logo 递归学习法 多进程 图标 Tracking 签证 FastAPI SAM 版权 域名 报税 Docker 飞书 Django CAM Qwen Heatmap Michelin Google Mixtral Vmess Use PIP PDB Attention C++ Card Cloudreve COCO git-lfs TensorRT Base64 腾讯云 Random 强化学习 OCR Jetson Pytorch CV Freesound Safetensors NameSilo DeepStream 第一性原理 财报 tqdm 搞笑 Permission v0.dev UNIX hf Vim Tensor Domain Sklearn UI TSV HuggingFace Template Plate Tiktoken Qwen2 Proxy Quantization Statistics Pickle Numpy PyCharm Paper Pillow Dataset Github XML Firewall TensorFlow RAR Image2Text ONNX LLM CLAP WAN Augmentation logger Baidu AI HaggingFace RGB WebCrawler PDF Datetime Windows NLTK LaTeX Jupyter Transformers BeautifulSoup Input 证件照 OpenAI Llama Ubuntu Shortcut 算法题 Math LoRA BF16 Streamlit Breakpoint GGML Git Qwen2.5 Hungarian Bert SVR JSON uWSGI Anaconda FP16 git PyTorch Disk EXCEL Hotel Bin Plotly Password ChatGPT uwsgi Paddle Color FlashAttention Hilton CSV VGG-16 云服务器 Agent VSCode Diagram Magnet InvalidArgumentError Conda XGBoost Bitcoin Claude
站点统计

本站现有博文324篇,共被浏览807387

本站已经建立2508天!

热门文章
文章归档
回到顶部