日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx虚拟主机、Nginx模块的安装使用(加密模块--with-http_ssl_module)

發布時間:2025/4/16 Nginx 150 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx虚拟主机、Nginx模块的安装使用(加密模块--with-http_ssl_module) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一,Nginx虛擬主機(一個nginx實現多個網站)

1,基于域名的虛擬主機

1)修改Nginx服務配置,添加相關虛擬主機配置如下

  • # vim /usr/local/nginx/conf/nginx.conf
  • .. ..
  • server {
  • ? ? ? ? ? ?listen 80;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//端口
  • ? ? ? ? ? ?charset UTF-8;?? ??? ?//開啟支持中文
  • ? ? ? ? ? ?server_name?admin.abc.xxxxxxxx.com ;? ? ? ? ? ? ? ? ? ? ? ? //域名
  • ? ? ? ? ? ?auth_basic "Input Password:";? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//認證提示符
  • auth_basic_user_file "/usr/local/nginx/pass";? ? ? ? ? ? ? //認證密碼文件
  • location / {
  • ? ? ? ? ? ? root html/;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //指定網站根路徑
  • ? ? ? ? ? ? index index.html index.htm;
  • ? ? ? ? ? ?}
  • ?
  • ? ? }
  • … …
  • ?
  • server {
  • ? ? ? ? ? ? ?listen 80;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //端口
  • ? ? ? ? ? ? ?server_name www.caizhan99.com;???????????????????????????? //域名
  • location / {
  • ? ? ? ? ? ? ? ? ? ? root www; ????????????????????????????????//指定網站根路徑
  • ? ? ? ? ? ? ? ? ? ? index index.html index.htm;
  • ? ? ? ? ? ?? }
  • ? ?}
  • 2)創建網站根目錄及對應首頁文件

    # mkdir /usr/local/nginx/www # echo "www" > /usr/local/nginx/www/index.html

    #cd /usr/local/nginx/
    #cat /html/index.html
    #mkdir www
    #echo "www? ?xxxxoooo " > /usr/local/nginx/tedu/index.html

    3) 重啟nginx服務

    # /usr/local/nginx/sbin/nginx -s reload

    4)測試

    firefox http://admin.abc.xxxxxxxx.com

    firefox http://www.caizhan99.com

    ***基于端口和IP省

    ?

    二,Nginx模塊的使用

    1,SSL虛擬主機(--with-http_ssl_module 模塊要安裝 )

    1)生成私鑰與證書(測試環境中自己生成,生產環境中購買)

  • ]# cd /usr/local/nginx/conf
  • [root@proxy ~]# openssl genrsa > cert.key? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//生成私鑰
  • [root@proxy ~]# openssl req -new -x509 -key cert.key > cert.pem ????//生成證書
  • 生產環境中用:

    2)修改Nginx配置文件,設置加密網站的虛擬主機

  • ~]# vim /usr/local/nginx/conf/nginx.conf
  • … …????
  • server {
  • ? ? ? ? ? ? listen 443 ssl;
  • ? ? ? ? ? ?server_name ???????? www.test.com;
  • ? ? ? ? ? ?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;
  • }
  • }
  • ?

    3)重啟服務

    ]# /usr/local/nginx/sbin/nginx -s reload

    4)測試

    ]# firefox https://www.c.com????????????//信任證書后可以訪問

    ?

    總結

    以上是生活随笔為你收集整理的Nginx虚拟主机、Nginx模块的安装使用(加密模块--with-http_ssl_module)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。