1. nginx配置https拜访

  • 1.1 应用 nginx -V产看编译参数中是否含有 --with-http_ssl_module ,如果没有则持续操作,如果有则跳到1.6步。留神:nginx如果曾经装置了其余模块,在装置新模块编译时,必须也要带上其余模块的编译参数,不然会抛弃掉其余模块! 编译参数就是通过nginx -V查看的!
  • 1.2 装置 OpenSSL

    yum -y install openssl openssl-devel
  • 1.3 在nginx的安装包目录下从新编译,留神不是 /usr/local/nginx/目录下,这是装置目录,不是安装包目录,编译要在安装包目录下进行,当然,装置目录下也没有configure这个可执行文件。

    ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  • 1.4 持续在安装包目录下执行make命令进行编译,留神为了保险起见,不要执行 make install这样会重新安装nginx,尽管很多人说执行没有关系,不会笼罩 nginx.conf文件,然而防着点总归没有错。

    make
  • 1.5 在make完之后,先停掉nginx服务。在安装包目录中有一个objs目录(跟configure可执行文件平级),将objs目录下的nginx文件复制到 /usr/local/nginx/sbin/目录下,笼罩掉其中的nginx可执行文件(当然,这里重名或者备份之后再删除,做好备份),命令如下:

    # 将编译实现的 nginx可执行文件 复制到 nginx的装置目录下的 sbin中,笼罩掉其中的nginxcp /nginx安装包目录/objs/nginx /usr/local/nginx/sbin/
  • 1.6 将SSL证书复制到 /usr/local/nginx/conf/目录中,如下名称:

    证书名称.pem证书名称.key
  • 1.7 批改/usr/local/nginx/conf/nginx.conf文件

    server {      listen       443 ssl;      server_name   证书对应的域名;      charset utf-8;      ssl_certificate      证书名称.pem;      ssl_certificate_key  证书名称.key;      ssl_session_cache    shared:SSL:1m;      ssl_session_timeout  5m;      ssl_ciphers  HIGH:!aNULL:!MD5;      ssl_prefer_server_ciphers  on;      ...上面是配置 location 内容}
  • 1.8 启动nginx,应用https拜访。
  • 1.9 将http申请转为 https申请

    # 在申请形式为 http的server中,所有的location下面增加如下代码rewrite ^(.*) https://$server_name$1 permanent;# 如果http申请端口不是80,则用上面的rewrite ^ https://$server_name$request_uri? permanent;

2. 一个server中配置多个动态资源的location时留神的问题

上面两个是动态资源的location,启动nginx没有问题,拜访 https://XXXX/a.png 也没有问题,然而拜访 https://XXXX/other/c.jpg 就呈现问题了,拜访不到。

location / {    root   /data/f;   try_files $uri $uri/ /index.html;}location /other/ {    root   /data/f;   try_files $uri $uri/ /index.html;}

解决办法:
/other/节点中的 root 改为 alias,如下:

location / {    root   /data/f;   try_files $uri $uri/ /index.html;}location /other/ {    alias   /data/f;   try_files $uri $uri/ /index.html;}

这样就能够失常拜访了。

3. 申请体过大

个别传递文件时,如过文件比拟大,则会报申请体过大的谬误,在nginx配置扩一下容就行了,在
http节点下增加 client_max_body_size 100m;如下:

http {    include       mime.types;      default_type  application/octet-stream;     client_max_body_size 100m;    ...上面时其余配置和server}