首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub

Summer

运维界的小白
首页
✨运维
🎉安装
👀踩坑
🤷‍♂️学习
😊关于
  • 分类
  • 标签
  • 归档
GitHub
  • Docker

  • Zabbix

  • Elasticsearch

  • K8s

  • Mysql

  • Redis

  • Nginx

    • 编译安装nginx
      • 1.解压源码包
      • 2.编译
      • 3.验证
      • (补充)4.Nginx做文件服务器 支持上传和下载
  • Prometheus

  • 安装
  • Nginx
summer
2020-11-18

编译安装nginx

# 1.解压源码包

  • 解压
[root@summer nginx]# tar xvf nginx-1.19.4.tar.gz
[root@summer nginx]# ll
total 1036
drwxr-xr-x 9 1001 1001    4096 Nov 18 17:49 nginx-1.19.4
-rw-r--r-- 1 root root 1054974 Nov 18 17:45 nginx-1.19.4.tar.gz
[root@summer nginx]# 

1
2
3
4
5
6
7

# 2.编译

  1. configure
[root@summer nginx-1.19.4]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --wule
checking for OS
 + Linux 3.10.0-957.21.3.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
...

1
2
3
4
5
6
7
8
9
10
  1. make
[root@summer nginx-1.19.4]# make
make -f objs/Makefile
make[1]: Entering directory `/home/summer/nginx/nginx-1.19.4'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_log.o \
	src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/ngx_palloc.o \
	src/core/ngx_palloc.c
...
1
2
3
4
5
6
7
8
9
10
11
12
13
  1. make install
[root@summer nginx-1.19.4]# make install
make -f objs/Makefile install
make[1]: Entering directory `/home/summer/nginx/nginx-1.19.4'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
...
1
2
3
4
5
6
7
8
9
10
11
12
13

# 3.验证

[root@summer sbin]# ./nginx 
[root@summer sbin]# ll
total 7216
-rwxr-xr-x 1 root root 7388072 Nov 18 17:50 nginx
[root@summer sbin]# cd ..
[root@summer nginx]# ll
total 36
drwx------ 2 nobody root 4096 Nov 18 17:57 client_body_temp
drwxr-xr-x 2 root   root 4096 Nov 18 17:50 conf
drwx------ 2 nobody root 4096 Nov 18 17:57 fastcgi_temp
drwxr-xr-x 2 root   root 4096 Nov 18 17:50 html
drwxr-xr-x 2 root   root 4096 Nov 18 17:57 logs
drwx------ 2 nobody root 4096 Nov 18 17:57 proxy_temp
drwxr-xr-x 2 root   root 4096 Nov 18 17:50 sbin
drwx------ 2 nobody root 4096 Nov 18 17:57 scgi_temp
drwx------ 2 nobody root 4096 Nov 18 17:57 uwsgi_temp
[root@summer nginx]# pwd
/usr/local/nginx
[root@summer nginx]# cd conf/
[root@summer conf]# ll
total 68
-rw-r--r-- 1 root root 1077 Nov 18 17:50 fastcgi.conf
-rw-r--r-- 1 root root 1077 Nov 18 17:50 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Nov 18 17:50 fastcgi_params
-rw-r--r-- 1 root root 1007 Nov 18 17:50 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Nov 18 17:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 18 17:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 18 17:50 mime.types
-rw-r--r-- 1 root root 5231 Nov 18 17:50 mime.types.default
-rw-r--r-- 1 root root 2656 Nov 18 17:50 nginx.conf
-rw-r--r-- 1 root root 2656 Nov 18 17:50 nginx.conf.default
-rw-r--r-- 1 root root  636 Nov 18 17:50 scgi_params
-rw-r--r-- 1 root root  636 Nov 18 17:50 scgi_params.default
-rw-r--r-- 1 root root  664 Nov 18 17:50 uwsgi_params
-rw-r--r-- 1 root root  664 Nov 18 17:50 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Nov 18 17:50 win-utf
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

此时访问ip:默认80端口即可(注意开放防火墙等)

# (补充)4.Nginx做文件服务器 支持上传和下载

  1. 下载nginx-upload模块并编译
[root@summer ]# yum install -y git gcc gcc-c++ pcre-devel openssl openssl-devel
[root@summer ]# git clone https://github.com/vkholodkov/nginx-upload-module/
[root@summer ]# tar -zxvf nginx-1.19.4.tar.gz 
[root@summer ]# ll
total 1032
drwxr-xr-x 9 1001 1001     186 Nov 24 21:59 nginx-1.19.4
-rw-r--r-- 1 root root 1054974 Nov 24 21:57 nginx-1.19.4.tar.gz
drwxr-xr-x 4 root root     279 Nov 24 21:58 nginx-upload-module
[root@summer ]# cd nginx-1.19.4
[root@summer ]# ./configure --with-compat --add-dynamic-module=../nginx-upload-module
[root@summer ]# make && make install

1
2
3
4
5
6
7
8
9
10
11
12
  1. 验证
  • 查看模块
[root@summer sbin]# ./nginx -V
nginx version: nginx/1.19.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --with-compat --add-dynamic-module=../nginx-upload-module
1
2
3
4
5
6
  • 新建几个验证文件
[root@summer summer]# touch file{1..10}
[root@summer summer]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 24 22:16 file1
-rw-r--r-- 1 root root 0 Nov 24 22:16 file10
-rw-r--r-- 1 root root 0 Nov 24 22:16 file2
-rw-r--r-- 1 root root 0 Nov 24 22:16 file3
-rw-r--r-- 1 root root 0 Nov 24 22:16 file4
-rw-r--r-- 1 root root 0 Nov 24 22:16 file5
-rw-r--r-- 1 root root 0 Nov 24 22:16 file6
-rw-r--r-- 1 root root 0 Nov 24 22:16 file7
-rw-r--r-- 1 root root 0 Nov 24 22:16 file8
-rw-r--r-- 1 root root 0 Nov 24 22:16 file9
1
2
3
4
5
6
7
8
9
10
11
12
13
  1. 配置
  • 用户密码配置
[root@summer ]# yum install -y httpd-tools
[root@summer ]# htpasswd -c /usr/local/nginx/conf/htpasswd summer
New password: 
Re-type new password: 
Adding password for user summer
1
2
3
4
5
  • nginx配置
user root;
worker_processes  1;

pid        logs/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;

    server {
        client_max_body_size 500m;
        listen       8097 default_server;
        listen       [::]:8097 default_server;
        server_name  _;
        autoindex   on;
        

        location / {
            root /home/summer;
            auth_basic "security download area";
            auth_basic_user_file "/usr/local/nginx/conf/htpasswd";
            autoindex on;
        }
    }

}
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

此时启动nginx后浏览器输入ip:8097

效果如下:

redis5安装说明
普罗米修斯安装

← redis5安装说明 普罗米修斯安装→

最近更新
01
redis持久化
12-08
02
redis为什么这么快
12-08
03
redis的优缺点
12-08
更多文章>
Theme by Vdoing | Copyright © 2019-2020 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式