nginx 搭建https服务器

来源:互联网 发布:宏观经济指标数据 编辑:程序博客网 时间:2024/06/05 04:41

安装在之前的文章中已经写过了。但是之前的安装出现了错误导致https没有安装成功。所以这里提一下大致的流程以及问题:

openssl :

version命令用来打印版本以及openssl其他各种信息。

用法:

[cpp] view plain copy
  1. openssl version [-a] [-v] [-b] [-o] [-f] [-p]  

参数说明:

-a:打印所有信息,相当于把其他optionset起来。当你向openssl官方站点报bug的时候,需要把这个指令列出来的东西也告诉他们。

-v:打印当前openssl的版本信息。

-b:打印当前版本的openssl是什么时候弄出来的。

-o 建立库的时候的各种于加密算法和机器字节有关的信息。

-f:编译时候的编译其的参数。

-p:平台信息。

注:不建议删除option会导致很多的问题,有依赖关系,会导致很多的命令和连带的服务不能使用。如果版本较老的话可以在下载历史版本的源码。下载地址:https://www.openssl.org/source/old/1.0.1/


nginx :


如果光靠编译解决不了,可以强制停止后,删除文件目录后重新安装

pkill -9 nginx //强制停止nginx服务

(1)安装编译:

./configure  --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module  --with-http_ssl_module --with-openssl=/root/Nginx/openssl-1.0.1e --with-pcre=/root/Nginx/pcre-8.35

make
make install    //如果不执行这部make install ;不然会把之前已经安装的nginx 覆盖掉

注:如果在安装编译时如果出现如下错误:POD document had syntax errors at /usr/bin/pod2man line 69. make .

解决办法如下: rm /usr/bin/pod2man    然后重新编译安装即可


(2)nginx配置文件

#user  nobody;user  root;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;    server {        listen       88;        server_name  localhost;        root   /www;        #charset koi8-r;        #access_log  logs/host.access.log  main;listen 443;    server_name localhost;    ssl on;    index index.html index.htm;    ssl_certificate   ../cert/214102827250341.pem;   #文件地址需要注意,ssl文件
    ssl_certificate_key  ../cert/214102827250341.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 / {            index  index.html index.htm index.php;#如果文件不存在则尝试TP解析            try_files  $uri  /index.php$uri;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        location ~ .+\.php($|/) {            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;#设置PATH_INFO,注意fastcgi_split_path_info已经自动改写了fastcgi_script_name变量,            #后面不需要再改写SCRIPT_FILENAME,SCRIPT_NAME环境变量,所以必须在加载fastcgi.conf之前设置            fastcgi_split_path_info  ^(.+\.php)(/.*)$;            fastcgi_param  PATH_INFO $fastcgi_path_info;            include        fastcgi.conf;        }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443 ssl;    #    server_name  localhost;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_cache    shared:SSL:1m;    #    ssl_session_timeout  5m;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers  on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}