一些python后端開發(fā)
ngrok
ngrok提供免費(fèi)的服務(wù)器,并且提供內(nèi)網(wǎng)穿透功能,可以把內(nèi)網(wǎng)某個(gè)端口反向代理到某個(gè)公網(wǎng)地址,需要注冊(cè)獲取token
nginx
nginx相比ngrok,可以反向代理多個(gè)服務(wù)器,并且實(shí)現(xiàn)負(fù)載均衡等策略
nginx安裝
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make && make install
如果之前安裝過nginx最好刪掉或者覆蓋,而不是直接make install
nginx配置文件
... #全局塊
events { #events塊
...
}
http #http塊
{
... #http全局塊
server #server塊
{
... #server全局塊
location [PATTERN] #location塊
{
...
}
location [PATTERN]
{
...
}
}
server
{
...
}
... #http全局塊
}
server塊:配置虛擬主機(jī)的相關(guān)參數(shù),一個(gè)http中可以有多個(gè)server。
location塊:配置請(qǐng)求的路由,以及各種頁面的處理情況。
########### 每個(gè)指令必須有分號(hào)結(jié)束。#################
#user administrator administrators; #配置用戶或者組,默認(rèn)為nobody nobody。
#worker_processes 2; #允許生成的進(jìn)程數(shù),默認(rèn)為1
#pid /nginx/pid/nginx.pid; #指定nginx進(jìn)程運(yùn)行文件存放地址
error_log log/error.log debug; #制定日志路徑,級(jí)別。這個(gè)設(shè)置可以放入全局塊,http塊,server塊,級(jí)別以此為:debug|info|notice|warn|error|crit|alert|emerg
events {
accept_mutex on; #設(shè)置網(wǎng)路連接序列化,防止驚群現(xiàn)象發(fā)生,默認(rèn)為on
multi_accept on; #設(shè)置一個(gè)進(jìn)程是否同時(shí)接受多個(gè)網(wǎng)絡(luò)連接,默認(rèn)為off
#use epoll; #事件驅(qū)動(dòng)模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 1024; #最大連接數(shù),默認(rèn)為512
}
http {
include mime.types; #文件擴(kuò)展名與文件類型映射表
default_type application/octet-stream; #默認(rèn)文件類型,默認(rèn)為text/plain
#access_log off; #取消服務(wù)日志
log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定義格式
access_log log/access.log myFormat; #combined為日志格式的默認(rèn)值
sendfile on; #允許sendfile方式傳輸文件,默認(rèn)為off,可以在http塊,server塊,location塊。
sendfile_max_chunk 100k; #每個(gè)進(jìn)程每次調(diào)用傳輸數(shù)量不能大于設(shè)定的值,默認(rèn)為0,即不設(shè)上限。
keepalive_timeout 65; #連接超時(shí)時(shí)間,默認(rèn)為75s,可以在http,server,location塊。
upstream mysvr {
server 127.0.0.1:7878;
server 192.168.10.121:3333 backup; #熱備
}
error_page 404 https://www.baidu.com; #錯(cuò)誤頁
server {
keepalive_requests 120; #單連接請(qǐng)求上限次數(shù)。
listen 4545; #監(jiān)聽端口
server_name 127.0.0.1; #監(jiān)聽地址
location ~*^.+$ { #請(qǐng)求的url過濾,正則匹配,~為區(qū)分大小寫,~*為不區(qū)分大小寫。
#root path; #根目錄
#index vv.txt; #設(shè)置默認(rèn)頁
proxy_pass http://mysvr; #請(qǐng)求轉(zhuǎn)向mysvr 定義的服務(wù)器列表
deny 127.0.0.1; #拒絕的ip
allow 172.18.5.54; #允許的ip
}
}
}
proxy_pass 后面最好別寫localhost,避免訪問host文件
https配置
http {
...
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/example.com.crt; # 證書文件路徑
ssl_certificate_key /path/to/example.com.key; # 私鑰文件路徑
# 如果有中間證書,也需要配置
ssl_trusted_certificate /path/to/intermediate.crt;
# 其他SSL配置參數(shù)
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3; # 支持的協(xié)議版本
ssl_ciphers ECDH:AESGCM:HIGH:!RC4:!DH:!MD5:!aNULL:!eNULL; # 使用此加密套件
ssl_prefer_server_ciphers on; # 優(yōu)先使用服務(wù)器端的加密套件
# 其他server配置...
}
...
}
其他的一些配置問題:https://blog.csdn.net/2301_76445860/article/details/144394051
gunicorn
gunicorn -w 4 -b 127.0.0.1:8080 app:app
其中app是app.py里的一個(gè)flask應(yīng)用
配置服務(wù)程序`http://www.rzrgm.cn/Ray-liang/p/4837850.html

浙公網(wǎng)安備 33010602011771號(hào)