Linux nginx安装

Linux nginx安装

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/;

        }

    }

}

  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值