centos 에서 https 서버 설정

4159 단어 nginxsslhttps 서버
이전 에는 줄곧 이해 하지 못 했 는데, 오늘 은 시간 을 좀 써 서 했 으 니, 그리 어렵 지 않다.
웹 서버 는 nginx 를 사용 합 니 다.
먼저 nginx 에 SSL 모듈 이 설치 되 어 있 는 지 확인 해 야 합 니 다. 다음 명령:
nginx -V

하면, 만약, 만약...
--with-http_ssl_module

그러면 설치 가 간단 합 니 다. 그렇지 않 으 면 nginx 를 컴 파일 하여 ssl 모듈 을 편집 해 야 합 니 다. 여기 서 자세히 설명 하지 않 으 면 구 글 에서 찾 을 수 있 습 니 다.
다음은 nginx 의 ssl 모듈 을 사용 해 야 합 니 다.내 nginx 버 전 은 1.2.6 으로 설치 가 끝 난 후에 예제 파일 을 보 여 주 었 다.
cd/etc/nginx/conf.d/
ls

다음 example 발견ssl. conf 파일.열 어 보 니 모두 주석 이 떨 어 졌 습 니 다. 우 리 는 주석 을 모두 열 고 다음 과 같이 바 꾸 었 습 니 다.
# HTTPS server
#
server {
listen       443;
server_name  demo;
ssl                  on;
#ssl_certificate      /etc/nginx/cert.pem;
ssl_certificate     /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
ssl_session_timeout  5m;
ssl_protocols  SSLv2 SSLv3 TLSv1;
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers   on;
location / {
root  /data/www;
index  index.html index.htm index.php;
}
location ~ \.php$ {
root          /data/www;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include        fastcgi_params;
}
}

여기 두 개의 파일 이 있 습 니 다. 하 나 는 cert. crt 이 고 다른 하 나 는 cert. key 입 니 다.
이 두 개 는 모두 인증 과 관련 된 문서 로 우 리 는 아직 없다.내부 네트워크 의 테스트 환경 이기 때문에 우 리 는 스스로 이 두 파일 을 생 성 할 수 있다.
생 성 방법 은 다음 과 같다.
1. 파일 을 만 들 디 렉 터 리 에 들 어가 서 openssl 로 서버 비밀 키 만 들 기
cd /etc/nginx/
openssl genrsa -des3 -out cert.key1024

이 때 알림:
Generating RSA private key, 1024 bit long modulus
......++++++
............................................................++++++
e is 65537 (0x10001)
Enter pass phraseforcert.key:
Verifying - Enter pass phraseforcert.key:

비밀 번 호 를 두 번 쓰 고 ls 를 다시 한 번 보면 / etc / nginx 에서 cert. key 파일 이 생 성 되 었 음 을 알 수 있 습 니 다.
2. 다음 에 cert. csr 파일, 즉 서명 요청 인증 서 를 생 성 합 니 다.이거 좀 귀찮아 요.
다음 명령 을 먼저 실행 합 니 다.
openssl req -new -key cert.key -out cert.csr

다음 과 같은 힌트 를 드 리 겠 습 니 다.
Enter pass phraseforcert.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter'.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) [Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:demo
Organizational Unit Name (eg, section) []:localhost
Common Name (eg, your name or your server'shostname) []:localhost
Email Address []:[email protected]
Please enter the following'extra'attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

주의 하 세 요. 사칭 뒤 에는 우리 가 작성 해 야 하 는 것 입 니 다. 마지막 두 개 는 모두 쓰 지 않 았 습 니 다.이치 에 따 르 면 빈 괄호 만 있 으 면 골 라 쓸 수 있 을 것 같다.
위의 실행 이 끝 난 후에 ls 를 한 번 더 하면 cert. csr 파일 이 나타 난 것 을 발견 할 수 있 습 니 다.
좋아, 우 리 는 반 까지 했다.더 내 려 가.
3. 복호화 후 비밀 키 만 들 기
먼저 cert. key 파일 을 cert. key. org 로 복사 합 니 다.
cpcert.key cert.key.org

그리고 다음 명령 을 수행 합 니 다.
openssl rsa -incert.key.org -out cert.key

이 때 다음 과 같은 힌트 가 나타 납 니 다.
Enter pass phraseforcert.key.org:

이전에 우리 가 설정 한 비밀 번 호 를 입력 하면 다음 과 같이 알려 줍 니 다.
writing RSA key

4. 다음 마지막 단 계 는 cert. csr 와 cert. key 로 cert. crt 파일 을 생 성 합 니 다.
다음 명령 을 수행 합 니 다:
openssl x509 -req -days 365 -incert.csr -signkey cert.key -out cert.crt

다음 과 같은 힌트 가 있다 면 성공 을 설명 합 니 다.
Signature ok

다시 ls 하면 cert. crt 파일 이 생 성 되 었 습 니 다.
이 때 nginx 를 다시 시작 합 니 다:
service nginx restart

좋아, 사고 가 나 지 않 으 면 모든 것 이 끝 이 야.
demo 도 메 인 이름 을 127.0.0.1 로 연결 하고 브 라 우 저 에 접근 합 니 다.https://demo효 과 를 볼 수 있 을 겁 니 다.
참고:http://blog.51yip.com/manual/nginx/

좋은 웹페이지 즐겨찾기