手機(jī)建網(wǎng)站怎么弄企業(yè)關(guān)鍵詞優(yōu)化最新報價
1,openresty 源碼安裝,帶ssl模塊
https://openresty.org/cn/download.html
(1)PCRE庫
PCRE庫支持正則表達(dá)式。如果我們在配置文件nginx.conf中使用了正則表達(dá)式,那么在編譯Nginx時就必須把PCRE庫編譯進(jìn)Nginx,因?yàn)镹ginx的HTTP模塊需要靠它來解析正則表達(dá)式。另外,pcre-devel是使用PCRE做二次開發(fā)時所需要的開發(fā)庫,包括頭文件等,這也是編譯Nginx所必須使用的。
(2)zlib庫
zlib庫用于對HTTP包的內(nèi)容做gzip格式的壓縮,如果我們在nginx.conf中配置了gzip on,并指定對于某些類型(content-type)的HTTP響應(yīng)使用gzip來進(jìn)行壓縮以減少網(wǎng)絡(luò)傳輸量,則在編譯時就必須把zlib編譯進(jìn)Nginx。zlib-devel是二次開發(fā)所需要的庫。
(3)OpenSSL庫
如果服務(wù)器不只是要支持HTTP,還需要在更安全的SSL協(xié)議上傳輸HTTP,那么需要擁有OpenSSL。另外,如果我們想使用MD5、SHA1等散列函數(shù),那么也需要安裝它。
apt-get install -y libssl-dev libpcre3 libpcre3-dev zlib1g-devwget https://openresty.org/download/openresty-1.27.1.1.tar.gztar -zxvf openresty-1.27.1.1.tar.gz
cd openresty-1.27.1.1/./configure
gmake && gmake install
Configuration summary+ using system PCRE library+ using system OpenSSL library+ using system zlib librarycp conf/nginx.conf '/usr/local/openresty/nginx/conf/nginx.conf.default'
test -d '/usr/local/openresty/nginx/logs' \|| mkdir -p '/usr/local/openresty/nginx/logs'
test -d '/usr/local/openresty/nginx/logs' \|| mkdir -p '/usr/local/openresty/nginx/logs'
test -d '/usr/local/openresty/nginx/html' \|| cp -R docs/html '/usr/local/openresty/nginx'
test -d '/usr/local/openresty/nginx/logs' \|| mkdir -p '/usr/local/openresty/nginx/logs'
gmake[2]: Leaving directory '/data/openresty-1.27.1.1/build/nginx-1.27.1'
gmake[1]: Leaving directory '/data/openresty-1.27.1.1/build/nginx-1.27.1'
mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifest
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty
2,增加openresty 沒有service服務(wù),開機(jī)啟動
增加一個服務(wù)配置
vi /etc/systemd/system/openresty.service
[Unit]
Description=OpenResty nginx server
After=network.target[Service]
Type=forking
ExecStart=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf
ExecReload=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf -s reload
ExecStop=/usr/local/openresty/bin/openresty -s stop
PrivateTmp=true[Install]
WantedBy=multi-user.target
然后重啟服務(wù):
# 配置變了,重新加載下
systemctl daemon-reload# 重啟服務(wù)
systemctl restart openresty# 增加開機(jī)啟動服務(wù):
systemctl enable openresty
3,自簽名證書,在OpenResty中配置SSL
OpenResty是一個基于Nginx的高性能Web平臺,支持多種功能擴(kuò)展。配置SSL可以使網(wǎng)站通過HTTPS協(xié)議進(jìn)行加密傳輸,提升安全性。以下是如何在OpenResty中配置SSL的步驟。
生成服務(wù)器私鑰和證書
首先,確保已經(jīng)安裝了OpenResty和OpenSSL。在OpenResty的配置目錄下創(chuàng)建一個cert文件夾,用于存放證書和私鑰。
mkdir -p /usr/local/openresty/nginx/conf/cert
cd /usr/local/openresty/nginx/conf/cert# 生成4096字節(jié)的服務(wù)器私鑰:
openssl genrsa -des3 -out server.key 4096# 創(chuàng)建簽名請求的證書(CSR):
openssl req -new -key server.key -out server.csr# 根據(jù)提示輸入相關(guān)信息,例如國家、州、省、市、組織名稱等。
# 去除私鑰的口令保護(hù):
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key# 生成證書文件:
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
5,配置Nginx.conf
編輯Nginx的配置文件nginx.conf,添加SSL相關(guān)配置。
server {listen 443 ssl;server_name localhost;ssl_certificate /usr/local/openresty/nginx/conf/cert/server.crt;ssl_certificate_key /usr/local/openresty/nginx/conf/cert/server.key;ssl_session_cache shared:SSL:5m;ssl_session_timeout 5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;ssl_prefer_server_ciphers on;location / {alias html/;index index.html index.htm;try_files $uri $uri/ /index.html;client_max_body_size 100M;
}
}
6,重啟Nginx
保存配置文件后,重啟Nginx以應(yīng)用新的配置。
sudo systemctl restart openresty
驗(yàn)證HTTPS
在瀏覽器中訪問配置的域名或IP地址,確保能夠通過HTTPS協(xié)議訪問網(wǎng)站。
將HTTP請求重定向到HTTPS
為了確保所有HTTP請求都重定向到HTTPS,可以在Nginx配置文件中添加以下配置:
server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
}
通過以上步驟,您可以在OpenResty中成功配置SSL,使網(wǎng)站支持HTTPS協(xié)議