keyword:域名申請(qǐng);域名解析;域名備案;服務(wù)器;服務(wù)器基礎(chǔ)配置;安裝SSL證書(shū);后臺(tái)搭建目錄1、整體描述2、服務(wù)器基礎(chǔ)配置3、后端框架4、dbsqlit1、整體描述訪問(wèn)網(wǎng)站的幾個(gè)方案" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

18143453325 在線咨詢 在線咨詢
18143453325 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 建站知識(shí) > 從零搭建帶域名的服務(wù)器后端

從零搭建帶域名的服務(wù)器后端

時(shí)間:2023-02-10 14:30:01 | 來(lái)源:建站知識(shí)

時(shí)間:2023-02-10 14:30:01 來(lái)源:建站知識(shí)

如何搭一個(gè)輸入https://www.xxx.com就能訪問(wèn)的網(wǎng)站?
keyword:域名申請(qǐng);域名解析;域名備案;服務(wù)器;服務(wù)器基礎(chǔ)配置;安裝SSL證書(shū);后臺(tái)搭建
目錄1、整體描述2、服務(wù)器基礎(chǔ)配置3、后端框架4、dbsqlit

1、整體描述

訪問(wèn)網(wǎng)站的幾個(gè)方案:

(1)輸入ip+port訪問(wèn)

服務(wù)器購(gòu)買 -> 服務(wù)器搭建Nginx

(2)通過(guò)(http://http://www.xxx.com)域名訪問(wèn)

服務(wù)器購(gòu)買 -> 服務(wù)器搭建Nginx ->域名購(gòu)買 -> 域名解析 -> 域名備案

(3)通過(guò)(https://http://www.xxx.com)域名訪問(wèn)

服務(wù)器購(gòu)買 -> 服務(wù)器搭建Nginx ->域名購(gòu)買 -> 域名解析 -> 域名備案-> 綁定SSL證書(shū)

會(huì)了第三種,前兩種自然不在話下,下文介紹第三種的實(shí)現(xiàn)方案。

2、服務(wù)器基礎(chǔ)配置

服務(wù)器配成centos,自帶python2

(1)nginx的安裝與配置

note:如果需要開(kāi)放多個(gè)端口(server),需要在阿里云/百度云服務(wù)器上去開(kāi)啟端口配置

nginx的依賴、安裝、編譯:

yum install gcc-c++yum install -y pcre pcre-develyum install -y zlib zlib-develyum install -y openssl openssl-develwget -c https://nginx.org/download/nginx-1.16.1.tar.gztar -zxvf nginx-1.16.1.tar.gz./configure --with-http_ssl_modulemake && make installcd /usr/local/nginx./sbin/nginx (-s stop/quit/reload)./sbin/nginx -s quit && ./sbin/nginxps aux|grep nginx 查看nginx服務(wù)vim /usr/local/nginx/conf/nginx.conf 修改端口,默認(rèn)80報(bào)錯(cuò)的情況下:(nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory))執(zhí)行sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf網(wǎng)站對(duì)應(yīng)的SSL證書(shū)下載后傳輸:

scp 1_www.domain.com_bundle.crt root@ip:/usr/local/nginx/conf/scp 2_www.domain.com.key root@ip:/usr/local/nginx/conf/修改nginx.conf,使得nginx依賴SSL證書(shū),參考文檔:

其中l(wèi)ocation的規(guī)范:如果都沒(méi)匹配到或者 location 寫(xiě)法為location / {} 則會(huì)請(qǐng)求默認(rèn)路徑(/nginx/html/)不知道為啥。。

整個(gè)nginx的搭建方案https://cloud.tencent.com/document/product/400/35244location的寫(xiě)法規(guī)范:https://blog.csdn.net/qq_35992647/article/details/88063167--把需要啟動(dòng)的網(wǎng)頁(yè)/war等放在nginx.conf指定的路徑下,啟動(dòng)nginx服務(wù),Done~

(2)Django框架搭建

1、yum/pip install django2、django-admin startproject calculator3、修改calculator/settings.py中的ALLOWED_HOSTS = []為ALLOWED_HOSTS = ['*']4、python manage.py runserver 0.0.0.0:8000上述四步可以開(kāi)啟服務(wù),可以訪問(wèn)了。詳細(xì)步驟參考:

https://blog.csdn.net/qq_43467898/article/details/83187698(3)django的數(shù)據(jù)庫(kù)使用

修改model文件,如:

class Person(models.Model): name = models.CharField(max_length=30) age = models.IntegerField() def __str__(self): return self.name然后是數(shù)據(jù)庫(kù)生效

生成變化/變化生效python manage.py makemigrationspython manage.py migrate3、uwsgi配置

在django項(xiàng)目manager.py同路徑下

yum install uwsgi詳細(xì)配置參考:https://blog.csdn.net/qq_43467898/article/details/83187698yum search uwsgi-plugin-pythonyum install uwsgi-plugin-python2(坑死)新建uwsgi.ini文件并添加 plugins = python(服務(wù)端口寫(xiě)成sock文件)uwsgi --ini uwsgi.ini 啟動(dòng)uwsgi服務(wù)nginx.conf配置添加如下,與uwsgi關(guān)聯(lián)

nginx在ngin.conf中配置sock地址,uwsgi也配置sock地址在uwsgi.ini中,最后nginx關(guān)聯(lián)sock再關(guān)聯(lián)uwsgi。

location ~ ^/calculate { // replace "path" to the path of your project uwsgi_pass unix:///"path"/calculator/calculator.sock; include /etc/nginx/uwsgi_params; }nginx重新啟動(dòng)服務(wù),OK!




【坑?。?!】conf/nginx.conf 和uwsgi通信的正確寫(xiě)法:

1、直接用ip:port通信

2、用127.0.0.1

3、location匹配上就完事了 其他都不用管

【conf/nginx.conf】 server { listen 443 ssl; server_name www.yzreal.com; ssl_certificate /usr/local/nginx/conf/1_www.yzreal.com_bundle.crt; ssl_certificate_key /usr/local/nginx/conf/2_www.yzreal.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location ~ ^/calculate { uwsgi_pass 127.0.0.1:3031; include uwsgi_params; } }【uwsgi.ini】[uwsgi]# django項(xiàng)目監(jiān)聽(tīng)的socket文件(可以使用端口代替)socket = 127.0.0.1:3031# django項(xiàng)目所在目錄chdir = .# django項(xiàng)目wsgi文件wsgi-file = ./calculator/wsgi.pymaster = trueprocesses = 2threads = 4vacuum = true# 通過(guò)touch reload可以重啟uwsgi服務(wù)器touch-reload = ./reload# 日志輸出daemonize = calculator.logplugins = python

4、dbsqllite

1、models.py里先創(chuàng)建表UserInfo : {username,password,age}

class UserInfo(models.Model): username = models.CharField(max_length= 50) password = models.CharField(max_length= 20) age = models.IntegerField(default = 0)然后需要生成數(shù)據(jù)庫(kù)變化(每次數(shù)據(jù)庫(kù)文件發(fā)生變化都要):

python manage.py makemigrationspython manage.py migrate2、查詢數(shù)據(jù)庫(kù)中所有table

sqlite3 db.sqlite3select name from sqlite_master;查詢:select * from CalculateApi_userinfo;select * from sqlite_master where type="table" and name="CalculateApi_userinfo";修改:update CalculateApi_userinfo set order_status = '0' where id = 124;刪除:delete from CalculateApi_userinfo where id = 206;.quit 導(dǎo)出到csv文件:sqlite3 -header -csv db.sqlite3 "select * from CalculateApi_userinfo;" > xxx.csv3、在view視圖里可以進(jìn)行數(shù)據(jù)庫(kù)增刪查改:

表名為:UserInfo結(jié)構(gòu)有:username,password,agefrom blog import models #導(dǎo)入blog模塊def db_handle(): # 增 (1)普通方式 models.UserInfo.objects.create(username='andy',password='123456',age=33) (2)字典方式 dic = {"username":"bruce","password":"123456","age":23} models.UserInfo.objects.create(**dic) # 刪 models.UserInfo.objects.filter(id=2).delete() # 查 user_list_obj = models.UserInfo.objects.all() user_list_obj 結(jié)構(gòu)是個(gè) list里套dict for obj in user_list_obj: print(obj.username, obj.password, obj.age) # 改 models.UserInfo.objects.filter(id=1).update(age=18) #找到id=1的數(shù)據(jù),將age改為184、查詢到的數(shù)據(jù)返回給請(qǐng)求端

def search(request): try: # get_all = UserInfo.objects.all().values() # datas 為 [{},{}] list中是dict datas = list(models.UserInfo.get_all()) result = { 'code': 0, 'message': 'success', 'data': datas, } except Exception as e: ret = 'Error: ' + str(e) return HttpResponse(ret) # 返回utf-8編碼的數(shù)據(jù) return JsonResponse(result)


5、上傳圖片

Linux下搭建ftp服務(wù) - ldsweely - 博客園

【Linux】安裝nginx,搭建圖片服務(wù)器_KAI丶的博客-CSDN博客

(1)花了半天解決的大坑,location配置的時(shí)候 :

root的處理結(jié)果是:root路徑+location路徑

alias的處理結(jié)果是:使用alias路徑替換location路徑

alias是一個(gè)目錄別名的定義,root則是上層目錄的定義。

還有一個(gè)重要的區(qū)別是alias后面必須要用“/”結(jié)束,否則會(huì)找不到文件的。。。而root則可有可無(wú)

(2)遇到403 forbidden的時(shí)候 要把django里的setting.py里的django.middleware.csrf.CsrfViewMiddleware 給注釋掉

(3)微信小程序后臺(tái)需要配置

uploadFile合法域名https://www.yzreal.com;






關(guān)鍵詞:服務(wù)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉