日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用腾讯云服务器发布网站

發布時間:2023/12/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用腾讯云服务器发布网站 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考資料

百度百科-域名綁定服務器IP
百度百科-網站綁定IP
Django官方推薦教程-Nginx+Gunicorn部署Django
CSDN-Nginx+Gunicorn部署Django
CSDN-nginx+gunicorn部署django項目

用到的工具軟件

  • FlashFXP:用于像服務器傳輸文件
  • Navicat:MySQL數據庫管理軟件

Django、Gunicorn、Nginx之間的關系

博客園

騰訊云服務器

騰訊云輕量服務器

域名

域名

域名與公網IP綁定

記錄管理->添加記錄->選擇www訪問->將你注冊號的云服務器的公網IP填寫進去->保存->更多操作->開啟

打開本地電腦的cmd
ping www.你的域名

服務器環境

  • pip
  • python
  • django
  • gunicorn
  • nginx

修改Django項目的settings文件

DEBUG = False# TrueALLOWED_HOSTS = ['你的域名']

服務器上的安裝

Gunicorn

pip3 install gunicorn

Nginx

CSDN-CentOS7.8安裝nginx

Gunicorn

官方教程
Gunicorn是純Python服務腳本,可以用于部署Django,最簡單的用法是在你的Django項目目錄下執行

gunicorn mysite.wsgi:application --bind 0.0.0.0:8000

如果要殺死Gunicorn進程

killall gunicorn

Nginx

Nginx是一個成熟的web服務,可以提供負載均衡和高并發處理。其實只使用Gunicorn也可以發布網站,但是推薦Nginx+Gunicorn這種方式發布Django網站項目

到/etc/nginx/
修改nginx.conf

worker_processes 1; user root; # 執行啟動nginx命令的用戶 # user nobody nogroup; # 'user nobody nobody;' for systems with 'nobody' as a group instead error_log /var/log/nginx/error.log warn; # 日志輸出位置 pid /var/run/nginx.pid;events {worker_connections 1024; # increase if you have lots of clientsaccept_mutex off; # set to 'on' if nginx worker_processes > 1# 'use epoll;' to enable for Linux 2.6+# 'use kqueue;' to enable for FreeBSD, OSX }http {include /etc/nginx/mime.types;# fallback in case we can't determine a typedefault_type application/octet-stream;access_log /var/log/nginx/access.log combined;sendfile on;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';# keepalive_timeout 65;include /etc/nginx/conf.d/*.conf;upstream app_server {# fail_timeout=0 means we always retry an upstream even if it failed# to return a good HTTP response# for UNIX domain socket setupsserver unix:/usr/PyCodes/Mysite/gunicorn.sock fail_timeout=0;# server 42.192.144.249:8000 fail_timeout=0;# for a TCP configuration# server 0.0.0.0:8000 fail_timeout=0;}server {# if no Host match, close the connection to prevent host spoofinglisten 80 default_server;return 444;}server {# use 'listen 80 deferred;' for Linux# use 'listen 80 accept_filter=httpready;' for FreeBSDlisten 80;client_max_body_size 4G;# set the correct host(s) for your siteserver_name afflatushare.com www.afflatushare.com; # 你的域名或IP(帶www和不帶www),多個域名或IP可用空格間隔keepalive_timeout 5;# path for static filesroot /usr/PyCodes/Mysite;# 你的項目位置location / {# checks for static file, if not found proxy to apptry_files $uri @proxy_to_app; # 項目文件位置}location @proxy_to_app {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $http_host;# we don't want nginx trying to do something clever with# redirects, we set the Host: header above already.proxy_redirect off;proxy_pass http://0.0.0.0:8000; # gunicorn啟動Django項目的端口}error_page 500 502 503 504 /500.html;location = /500.html {root /path/to/app/current/public;}} }

啟動Nginx

systemctl start nginx

重啟

nginx -s reload

看報錯

開發者工具->Console

我的網站

http://www.afflatushare.com/

總結

以上是生活随笔為你收集整理的使用腾讯云服务器发布网站的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。