1. 程式人生 > 其它 >nginx安裝,https nginx-1.19.0

nginx安裝,https nginx-1.19.0

技術標籤:nginx

一般常用命令

進入sbin目錄下

cd /usr/local/nginx/sbin

啟動
./nginx 

關閉
./nginx -s stop 

重啟
./nginx -s reload 

檢查配置
./nginx -t 

安裝 官網下載

解壓

tar -zxvf nginx-1.19.0.tar.gz

進入目錄

cd nginx-1.19.0

執行命令

./configure

執行make命令

make

執行make install命令

make install

出錯 make: *** No rule to make target `build', needed by `default'. Stop

更新yum

yum update

yum -y install openssl openssl-devel

更新完成後,先刪除之前準備make的nginx包,然後重新解壓一個。

配置nginx.conf

開啟配置檔案

vim /usr/local/nginx/conf/nginx.conf

修改配置檔案

server {

    listen 8080; #監聽埠

    server_name 192.168.101.10; #本機主機名

    location / {

    root /data/scan_root; #資料存放地址

    autoindex on; #樹形顯示目錄

    }

}

訪問 nginx 403 Forbidden

在conf/nginx.conf中修改user的許可權 改成root 第一行

配置 https證書

來到解壓目錄下後

./configure --with-http_ssl_module

注意如果沒有出現錯誤

執行make命令

備份當前檔案

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

rm -r /usr/local/nginx/sbin/nginx

cp objs/nginx /usr/local/nginx/sbin/nginx

到 /usr/local/nginx 執行

./sbin/nginx -V

重新啟動

新增conf 配置項

nginx.conf http 下新增程式碼

include /usr/local/nginx/conf/conf.d/*.conf;

新增 資料夾

/usr/local/nginx/conf/conf.d

新增配置檔案即可liulangdy.cn.conf

server {
    listen 443 ssl;
    server_name *.liulangdy.cn;

    #證書檔案
    ssl_certificate     /usr/local/nginx/conf/cert/liulangdy.pem;
    #私鑰檔案
    ssl_certificate_key /usr/local/nginx/conf/cert/liulangdy.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;
        root /data/web/test.liulangdy.com;
        index index.html index.htm;
    }
}

server {
    listen 80;
    server_name *.liulangdy.cn;
    return 301 https://$http_host$request_uri;
    #rewrite ^(.*)$ https://liulangdy.cn permanent;
}