成人AV在线无码|婷婷五月激情色,|伊人加勒比二三四区|国产一区激情都市|亚洲AV无码电影|日av韩av无码|天堂在线亚洲Av|无码一区二区影院|成人无码毛片AV|超碰在线看中文字幕

lnmp 強(qiáng)制跳轉(zhuǎn)https

1,訪問(wèn)時(shí)出現(xiàn) 502 Bad Gateway 的解決辦法Nginx 502 Bad Gateway的含義是請(qǐng)求的php-cgi 已經(jīng)執(zhí)行,但是由于某種原因(一般是讀取資源的問(wèn)題)沒(méi)有執(zhí)行完畢而導(dǎo)致p

1,訪問(wèn)時(shí)出現(xiàn) 502 Bad Gateway 的解決辦法

Nginx 502 Bad Gateway的含義是請(qǐng)求的php-cgi 已經(jīng)執(zhí)行,但是由于某種原因(一般是讀取資源的問(wèn)題)沒(méi)有執(zhí)行完畢而導(dǎo)致php-cgi 進(jìn)程終止。一般并發(fā)數(shù)太高的網(wǎng)站都容易出現(xiàn)此錯(cuò)誤。出現(xiàn)502 Bad Gateway的原因有很多(更多原因見(jiàn)這里),但是大部分人修改下面的參數(shù)即可解決。

打開(kāi) /usr/local/php/etc/php-fpm.conf 文件,修改如下幾個(gè)參數(shù):

5

0s

5s

max_children表示php-cgi 的處理進(jìn)程。如果max_children設(shè)置的較小,比如5-10個(gè),那么php-cgi 就會(huì)“很累”,處理速度也很慢,等待的時(shí)間也較長(zhǎng)。如果長(zhǎng)時(shí)間沒(méi)有得到處理的請(qǐng)求就會(huì)出現(xiàn)504 Gateway Time-out錯(cuò)誤。設(shè)置max_children也需要根據(jù)服務(wù)器的性能進(jìn)行設(shè)定,增大進(jìn)程數(shù),內(nèi)存占用也會(huì)相應(yīng)增大,正常情況下每個(gè)php-cgi 所耗費(fèi)的內(nèi)存在20M 左右,這里我設(shè)置的是80。

request_terminate_timeout指的是fast-cgi 的執(zhí)行腳本時(shí)間,它默認(rèn)是0s 。0s 的含義是讓php-cgi 一直執(zhí)行下去而沒(méi)有時(shí)間限制。如果你在此設(shè)成0s ,那么當(dāng)出現(xiàn)502 Bad Gateway的時(shí)候,這個(gè)502的狀態(tài)將一直持續(xù)下去不會(huì)改變。但是如果你設(shè)置成5s ,那么當(dāng)php-cgi 假死5s 以后會(huì)自動(dòng)恢復(fù)。這個(gè)值可以根據(jù)你服務(wù)器的性能進(jìn)行設(shè)定,這里我設(shè)置的是20s 。

2,強(qiáng)制開(kāi)啟SSL (強(qiáng)制http 轉(zhuǎn)向https )

編輯 /usr/local/nginx/conf/nginx.conf 文件,修改如下代碼:

server

{ listen 80; server_name 域名; rewrite ^/(.*) https://域名/$1 permanent;

,

}

server

ssl on; { listen 443; server_name 域名; index index.html index.htm index.php; root /home/wwwroot;

ssl_certificate /home/wwwroot/xxx.crt;

ssl_certificate_key /home/wwwroot/xxx.key;

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;

ssl_ciphers ALL:!ADH:!EXPORT56:RC4 RSA: HIGH: MEDIUM: LOW: SSLv2: EXP; ssl_prefer_server_ciphers on;

location ~ .*.(php|php5)?$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; fastcgi_param HTTPS on;

,

}

3,同時(shí)使http 和https 都能正常訪問(wèn)

這個(gè)問(wèn)題浪費(fèi)了我巨大的精力,其實(shí)新建兩個(gè)server 就能解決,但是我在試驗(yàn)的過(guò)程中,發(fā)現(xiàn)有兩個(gè)問(wèn)題需要注意:

1,兩個(gè)server 里不能同時(shí)出現(xiàn)“l(fā)og_format access”這一段,否則重啟nginx 會(huì)提示配置文件有誤。

2,必須在443端口加上“fastcgi_param HTTPS on;”,否則在https 進(jìn)行提交表單操作時(shí)會(huì)轉(zhuǎn)向http 。

整個(gè)配置如下:

server

location ~ .*.(php|php5)?$ { } fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; { listen 80; server_name 域名; index index.html index.htm index.php; root /home/wwwroot;

,

location /status {

stub_status on;

access_log off;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {

expires 30d; }

location ~ .*.(js|css)?$

{

expires 12h; }

}

server

{

listen 443; ssl on; ssl_certificate /home/wwwroot/xxx.crt;

,

ssl_certificate_key /home/wwwroot/xxx.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1;

ssl_ciphers

ALL:!ADH:!EXPORT56:RC4 RSA: HIGH: MEDIUM: LOW: SSLv2: EXP;

location /status {

stub_status on; } location ~ .*.(php|php5)?$ { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; fastcgi_param HTTPS on; server_name 域名; index index.html index.htm index.php; root /home/wwwroot; ssl_prefer_server_ciphers on;

,

access_log off;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)?$

{

expires 12h;

}

log_format access '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

access_log /home/wwwlogs/access.log access;

}

標(biāo)簽: