windows下phpstudy環境部署通路https項目
安裝證書
- 安裝openssl,網上教程很多,這裡不贅述,隻要可以運作openssl即可
- 建立私鑰
#會輸入密碼,不少于四位,記住,下面需要用
openssl genrsa -des3 -out private.key 1024
- 建立csr證書
#這裡需要輸入上面的密碼,配置過程中需要寫一堆參數,處理Common Name需要寫域名資訊,其他的随便寫即可
openssl req -new -key private.key -out private.csr
#這裡可能會報錯,報錯是因為配置檔案錯誤,找到檔案位址直接重新設定下即可,這裡的指令我記不清了,找到後會在評論回複
- 去掉密碼
#這裡不是強求的,可以不操作,不過加載檔案時,需要輸入密碼
openssl rsa -in private.key -out private_no_pwd.key
- 生成crt證書
openssl x509 -req -days 365 -in private.csr -signkey private_no_pwd.key -out private.crt
配置nginx
- 建立項目,配置好域名和路徑資訊,需要注意的是,添加的域名端口要寫80
- 修改conf檔案
#這裡是我的配置檔案,可以參考使用
server {
listen 80;
listen 443 ssl; #注意,這裡需要寫ssl,否則浏覽器會報錯
server_name 域名資訊;
root "項目路徑";
ssl_certificate "crt路徑,需要寫絕對路徑";
ssl_certificate_key "key路徑,需要寫絕對路徑";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .+\.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 700;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
include fastcgi.conf;
}
if ( !-e $REQUEST_FILENAME )
{
rewrite ^/(.*)$ /index.php?url=$1 last;
}
location ~ /\.ht {
deny all;
}
}
- 重新開機nginx後即可正常通路