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

本站现有博文332篇,共被浏览875137

本站已经建立2583天!

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