这里只是讲的Nginx结合SSL的一个非常简单的应用,仅供测试环境下使用,暂时不讨论实际生产环境里的应用。
创建各种证书:
- cd /usr/local/nginx/conf
- openssl genrsa -des3 -out server.key 1024
- openssl req -new -key server.key -out server.csr
- cp server.key server.key.org
- openssl rsa -in server.key.org -out server.key
- openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
中间会出现要输入密码的过程,便于管理,输入相同的密码就可以了。
Nginx配置:
- server {
- listen 80;
- server_name www.luxiaok.com;
- root /luxiaok.com;
- index index.php;
- location ~ .*\.(php|php5) {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi.conf;
- }
- }
- server {
- listen 443;
- server_name www.luxiaok.com;
- ssl on;
- ssl_certificate /usr/local/nginx/conf/server.crt;
- ssl_certificate_key /usr/local/nginx/conf/server.key;
- root /luxiaok.com;
- index index.php;
- location ~ .*\.(php|php5) {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi.conf;
- }
- }
这是在LNMP架构下的虚拟主机的示例配置文件了。
然后重新加载Nginx配置文件就可以了。
转载于:https://blog.51cto.com/luxiaok/1151946