网站https访问设置证书

分享
开发者 2024-9-20 17:00:59 62 0 来自 中国
一、安装Nginx


  • 安装Nginx
mkdir applicationcd application/wget https://nginx.org/en/download/nginx-1.22.0.tar.gztar -zxvf nginx-1.22.0.tar.gz

  • 运行初始化设置
cd ./nginx-1.22.0./configure

  • 假如出现提示错误, 大概是依靠包乜有安装需要安装
# 提示 pcre libraryyum install -y pcre pcre-devel#提示 c++ compile flagsyum  -y install  gcc gcc-c++#提示 zlib libraryyum install -y zlib-devel安装后再次运行
cd ./nginx-1.22.0./configure

  • 编译
make

  • 安装
make install

  • 运行 nginx
whereis nginxnginx: /usr/local/nginxcd /usr/local/nginx./sbin/nginx

  • 检察是否运行乐成
ps -ef | grep nginx

  • 欣赏器访问 localhost:80
  • 其他下令
cd /usr/local/nginx./sbin/nginx    #启动./sbin/nginx -s reload  #'重启./sbin/nginx  -s stop #关闭./sbin/nginx -s quit   #哀求处理惩罚完后才关闭参考:https://blog.csdn.net/Cs_Mervyn/article/details/120075477
二、 Nginx 的 SSL 模块安装


  • 检察 nginx 是否安装 http_ssl_module 模块。
$ /usr/local/nginx/sbin/nginx -V假如出现 configure arguments: –with-http_ssl_module, 则已安装(下面的步调可以跳过,进入 nginx.conf 设置)。
1.1 设置ssl
$ cd nginx-1.20.0$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module1.2 重新编译
make 下令编译(利用make install会重新安装nginx),此时当前目次会出现 objs 文件夹。
1.3
用新的 nginx 文件覆盖当前的 nginx 文件。
$ cp ./objs/nginx /usr/local/nginx/sbin/1.4 验证
再次检察安装的模块(configure arguments: –with-http_ssl_module分析ssl模块已安装)。
$ /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.15.9configure arguments: --with-http_ssl_module三、设置证书


  • 进入设置文件中
cd /usr/local/nginx/conf/cat nginx.conf 设置如下
    #user  nobody;    # 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是 http哀求的 直接都解释了
    #server {     #   listen       80;      #  server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;       # location / {        #    root   html;         #   index  index.html index.htm;        #}        #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$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    #}下面的HTTPS server 举行设置
    # 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  XXX.XXX.com;   # 设置重定向        location / {                proxy_pass  http://127.0.0.1:8080; # 转发规则        proxy_set_header Host $proxy_host; # 修改转发哀求头,让8080端口的应用可以受到真实的哀求        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;     }      # 设置证书的信息        ssl_certificate      /usr/local/nginx/XXX.pem;        ssl_certificate_key  /usr/local/nginx/XXX.key;        ssl_session_cache    shared:SSL:1m;        ssl_session_timeout  5m;        ssl_ciphers  HIGH:!aNULL:!MD5;        ssl_prefer_server_ciphers  on;            }}末了重启  输入设置的server_name就可以举行访问;
cd /usr/local/nginx./sbin/nginx -s reload  #'重启留在末了的话


  • Nginx的作用是什么
  • Nginx的正向署理 和反向署理是什么意思
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-19 02:23, Processed in 0.158471 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表