ssl證書安裝完後,https訪問後下載index檔案,HTTP訪問正常的。Nginx ssl設定後自動下載根目錄的index.php而不是載入
阿新 • • 發佈:2018-11-15
給Nginx安裝ssl證書,https訪問後,重新自動下載index.php檔案。一開始的Nginx的配置檔案如下:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on
上面部分程式碼無關,我就沒有展出來
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate server.pem;
ssl_certificate_key server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
}
然後:就是出現下載檔案的現象。後來百度他們說,是因為Nginx伺服器沒有和PHP正確通訊的原因。
然後我就把上面的HTTp服務的配置,覆蓋了下面的location /{} 了。後來開啟後,還是出現下載問題。
nginx 和PHP通訊:就是把HTTP協議下,通訊的方法拿了過來。記得:location /{} 不能重複出現。
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate server.pem;
ssl_certificate_key server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_prefer_server_ciphers on;
location ~ \.php{
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$; #增加這一句
fastcgi_param PATH_INFO $fastcgi_path_info; #增加這一句
include fastcgi_params;
fastcgi_param HTTPS on;
}
location / {
root html;
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~* \.(jpg|jpeg|png|gif|webp)$ {
expires 30d;
}
location ~* \.(css|js)$ {
expires 7d;
}
}
這就奇了怪了,為什麼呢?他們說有可能是谷歌瀏覽器的快取問題。然後我就換成其他瀏覽器了 ,再重新開啟就好了。真是一億萬個無語啊。
大家在記得在server下,配置好後,清理快取。再試下了。