keyword:域名申請(qǐng);域名解析;域名備案;服務(wù)器;服務(wù)器基礎(chǔ)配置;安裝SSL證書(shū);后臺(tái)搭建目錄1、整體描述2、服務(wù)器基礎(chǔ)配置3、后端框架4、dbsqlit1、整體描述訪問(wèn)網(wǎng)站的幾個(gè)方案" />
時(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
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ū),參考文檔:整個(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~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ù)使用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 migrate
3、uwsgi配置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)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】 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
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 migrate
2、查詢數(shù)據(jù)庫(kù)中所有tablesqlite3 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.csv
3、在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改為18
4、查詢到的數(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)
關(guān)鍵詞:服務(wù)
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。