随笔 - 118  文章 - 0 评论 - 341 阅读 - 299万
< 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

1. 说明

操作系统:CentOS 7.4 64位

nginx版本:1.16.1

安装日期:2019/10/01

 

2. 开始安装

2.1 安装运行库

1
$ yum -y install gcc gcc-c++ automake autoconf libtool make

 

2.2 安装openssl

说明:nginx SSL使用。

1
2
3
$ cd /usr/local/src
$ wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
$ tar -zxvf openssl-1.0.1t.tar.gz

  

2.3 安装pcre

说明:pcre是一个正则表达式库。

1
2
3
4
5
6
7
$ cd /usr/local/src
$ wget https://ftp.pcre.org/pub/pcre/pcre-8.38.tar.gz
$ tar -zxvf pcre-8.38.tar.gz
$ cd pcre-8.38
$ ./configure
$ make
$ make install

 

2.4 安装zlib

说明:zlib是提供数据压缩用的函式库。

1
2
3
4
5
6
7
$ cd /usr/local/src
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ make install

 

2.5 安装nginx

说明:此示例的nginx版本为1.16.1。

1
2
3
4
5
6
7
8
9
10
11
12
$ cd /usr/local/src
$ wget http://nginx.org/download/nginx-1.16.1.tar.gz
$ tar -zxvf nginx-1.16.1.tar.gz
$ cd nginx-1.16.1
 
$ ./configure --with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.38 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t
 
$ make
$ make install

 

3. 操作nginx

3.1 启动nginx

说明:nginx默认安装路径为 /usr/local/nginx

1
2
$ cd /usr/local/nginx
$ ./sbin/nginx

 

3.2 加载配置

1
2
/usr/local/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/nginx/sbin/nginx -s reopen            # 重启 Nginx

 

3.3 停止nginx

1
$ /usr/local/nginx/sbin/nginx -s stop

 

4. nginx配置文件

说明:包含80、443(SSL)以及反向代理。

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#user  root;
worker_processes 2;
 
#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;
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    upstream api {
            server localhost:7001;
    }
 
    server {
        listen 80;
        listen 443 ssl;
        server_name www.test.com;
        #ssl on;
        root /usr/local/nginx/html;
        index index.html index.htm;
        ssl_certificate      /usr/local/nginx/cert/test.com.pem;
        ssl_certificate_key  /usr/local/nginx/cert/test.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 / {
            root /usr/local/nginx/html/dist;
            expires 1h;
        }
 
        # api
        location ^~ /api/ {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://api/;
        }
    }
}

  

 

posted on   FangMu  阅读(3173)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示