随笔 - 165, 文章 - 0, 评论 - 18, 阅读 - 22万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

编译nginx并支持ssl

Posted on   火冰·瓶  阅读(148)  评论(0编辑  收藏  举报

1.安装依赖包

apt update
apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
apt-get install openssl
apt-get install libssl-dev

apt-get install gcc   libpcre3   libpcre3-dev   zlib1g   zlib1g-dev   openssl   libssl-dev  -y

 

2.下载nginx源码并解压
mkdir work
cd work
wget http://nginx.org/download/nginx-1.22.1.tar.gz
tar zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1

 

3.编译并安装

#prefix后面的路径是编译后安装nginx的路径
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

 

4.检查
cd /usr/local/nginx/sbin
./nginx -V
./nginx -t

 

5.设置开机自动启动 

crontab -e

输入:

@reboot /usr/local/nginx/sbin/nginx

然后 reboot 重启服务器

 

6.配置
打开配置文件nginx.conf,路径为:/usr/local/nginx/conf/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
server {
listen 80;
server_name t1.xxx.net;
location / {
    proxy_pass http://localhost:50000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }
}
 
 
 
 
server{
    listen 80;
    server_name t2.aaaa.com;
    rewrite ^(.*)$ https://${server_name}$1 permanent; #设置http自动转发https
}
 
 
 
server {
listen 443 ssl;
server_name t2.aaaa.com;
ssl_certificate      /root/ssl/xxx.pem;
ssl_certificate_key  /root/ssl/xxx.key;
 
ssl_session_cache    shared:SSL:1m;
ssl_session_timeout  5m;
 
ssl_ciphers  HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers  on;
location / {
    proxy_pass http://localhost:50001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }
}

  

 

7.常用命令  

./nginx
./nginx -s reload
./nginx -s stop

 

相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示