Linux安装nginx 支持ssl(https)

790 阅读1分钟

1、下载nginx系统依赖以及https支持模块

    yum -y install gcc gcc-c++ autoconf automake libtool make cmake

    yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

2、/root目录下载nginx安装包

  wget http://nginx.org/download/nginx-1.22.1.tar.gz

4、解压

tar -xvf nginx-1.22.1.tar.gz

5、修改文件名为nginx

mv nginx-1.22.1 nginx

6、进入nginx文件夹

cd nginx

7、构建环境

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre

8、编译&安装

make && make install

9、修改nginx配置文件 /usr/local/nginx/conf/nginx.conf

vi /usr/local/nginx/conf/nginx.conf

给大家看下我的配置案例,有需要自己修改

    user  root;
    worker_processes  1;

    error_log  logs/error.log;

    events {
        worker_connections  1024;
    }


    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;

        server {
            listen       80;
            server_name  localhost;
            root /var/www;
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }

        # HTTPS server
        server {
            listen 443 ssl;
            server_name localhost;
            root /var/www;
            index index.html index.htm;
            client_max_body_size 2000M;
            client_body_buffer_size 2000M;
            fastcgi_intercept_errors on;
            ssl_certificate /root/ssl/8652634_www.wzrlt.com_nginx/8652634_www.wzrlt.com.pem;
            ssl_certificate_key /root/ssl/8652634_www.wzrlt.com_nginx/8652634_www.wzrlt.com.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 /MP_verify_NpGzq0vIOPKCwrRS.txt{
                    root /usr/local/nginx/html;
            }
            location /PEt6hJgt0I.txt {
                root /usr/local/nginx/html;
            }
            location /MP_verify_0ASzvTT6RU7ofwZf {
                root /usr/local/nginx/html;
            }
            location /login/MP_verify_0ASzvTT6RU7ofwZf {
                    root /usr/local/nginx/html;
             }
            location /{
                root /usr/local/nginx/html/dist;
                try_files $uri /index.html;
            }
            location /admin{
               alias /usr/local/nginx/html/admin/dist;
               # 非根目录
               try_files $uri $uri/ @router;
            }
            location @router{
                rewrite ^.*$ /admin/index.html last;
            }
            location /server/ {
                proxy_pass http://localhost:3232/;
            }
       }
    }

10、最后指定配置文件运行 nginx 即可

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf