Nginx + php + http / https 서버 설정
6499 단어 개발 환경 설정
SSL 인증서 설명
블 로 거들 이 사용 하 는 DV 무료 인증서 테스트
SSL Key 와 CSR 파일 또는 PEM 파일 에 대하 여
일반 SSL 배급 사 에서 키 나 csr 를 제공 합 니 다.없 으 면 스스로 생 성 할 수 있 고 OpenSSL 을 사용 합 니 다.
.key
비밀 키 입 니 다.HTTPS 설정
먼저 nginx 호스트 설정 디 렉 터 리 에 들 어가 야 합 니 다: / var / nginx / sites - enabled * * 설정 https 와 http 는 두 가지 방식 이 있 습 니 다.
server {
listen 80;# 80 443
listen 443 ssl;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
#
ssl_certificate example.com.crt;
#
ssl_certificate_key example.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#php
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
강제 http 점프 https
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl on;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
ssl_certificate example.com.curl;
ssl_certificate_key example.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
# deny .git access
location ~ /\.git {
deny all;
}
}
참조: 주소 1