CentOS系列教程(四)

源码编译安装Nginx的依赖包(pcre-8.43.tar.gz zlib-1.2.11.tar.gz)并安装Nginx(nginx-1.16.1.tar.gz)

[ tar]# cp * /usr/local/src/
[ src]# cd /usr/local/src/
[ src]# ls
nginx-1.16.1.tar.gz pcre-8.43.tar.gz zlib-1.2.11.tar.gz
[ src]# tar -xzvf pcre-8.43.tar.gz
pcre-8.43/testdata/testinput19
pcre-8.43/testdata/testoutput11-16
pcre-8.43/testdata/testoutput17
pcre-8.43/pcre32_config.c
pcre-8.43/RunTest
.................................................................................................................
pcre-8.43/pcre32_ucd.c
pcre-8.43/makevp_l.txt
[ src]# ls
nginx-1.16.1.tar.gz pcre-8.43 pcre-8.43.tar.gz zlib-1.2.11.tar.gz
[ src]# tar -xzvf zlib-1.2.11.tar.gz
zlib-1.2.11/
zlib-1.2.11/adler32.c
...................................................................................................................
zlib-1.2.11/amiga/Makefile.pup
zlib-1.2.11/amiga/Makefile.sas
[ src]# ls
nginx-1.16.1.tar.gz pcre-8.43 pcre-8.43.tar.gz zlib-1.2.11 zlib-1.2.11.tar.gz
[ src]# cd zlib-1.2.11
[ zlib-1.2.11]# ls
adler32.c contrib examples gzwrite.c inflate.c make_vms.com README watcom zlib.3 zutil.c
amiga crc32.c FAQ INDEX inflate.h msdos test win32 zlib.3.pdf zutil.h
ChangeLog crc32.h gzclose.c infback.c inftrees.c nintendods treebuild.xml zconf.h zlib.h
CMakeLists.txt deflate.c gzguts.h inffast.c inftrees.h old trees.c zconf.h.cmakein zlib.map
compress.c deflate.h gzlib.c inffast.h Makefile os400 trees.h zconf.h.in zlib.pc.cmakein
configure doc gzread.c inffixed.h Makefile.in qnx uncompr.c zlib2ansi zlib.pc.in
[ zlib-1.2.11]#
[ zlib-1.2.11]# ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
[ zlib-1.2.11]# make && make install
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o adler32.o adler32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o crc32.o crc32.c
.................................................................................................................................................
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
[ zlib-1.2.11]#
[ zlib-1.2.11]# cd ..
[ src]# ls
nginx-1.16.1.tar.gz pcre-8.43 pcre-8.43.tar.gz zlib-1.2.11 zlib-1.2.11.tar.gz
[ src]# tar -xzvf nginx-1.16.1.tar.gz
nginx-1.16.1/
nginx-1.16.1/auto/
nginx-1.16.1/conf/
nginx-1.16.1/contrib/
nginx-1.16.1/src/
..................................................................................................................................................
nginx-1.16.1/auto/cc/owc
nginx-1.16.1/auto/cc/sunc
[ src]# ls
nginx-1.16.1 nginx-1.16.1.tar.gz pcre-8.43 pcre-8.43.tar.gz zlib-1.2.11 zlib-1.2.11.tar.gz
[ src]# cd nginx-1.16.1
[ nginx-1.16.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[ nginx-1.16.1]#
[ nginx-1.16.1]# ./configure --with-pcre=/usr/local/src/pcre-8.43
checking for OS

  • Linux 3.10.0-957.1.3.el7.x86_64 x86_64
    checking for C compiler ... found
  • using GNU C compiler
    .......................................................................................................................
    nginx http scgi temporary files: "scgi_temp"

[ nginx-1.16.1]#
[ nginx-1.16.1]# make && make install
src/core/ngx_proxy_protocol.c
.........................................................................................................................
test -d ‘/usr/local/nginx/logs‘ \
|| mkdir -p ‘/usr/local/nginx/logs‘
make[1]: Leaving directory `/usr/local/src/nginx-1.16.1‘
[ nginx-1.16.1]#
[ nginx-1.16.1]# cd /usr/local/
[ local]# ls
bin games kafka-manager lib64 nohup.out server1.log sms_off_file.json test.py
dealSmsLog.py include kafka-manager-master libexec out_sms.log share src t.log
etc kafka2.12 lib nginx sbin sms.log test.log zookeeper
[ local]# cd nginx/
[ nginx]# ls
conf html logs sbin
[ nginx]# cd conf/
[ conf]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[ conf]# cat -n nginx.conf
1
2 #user nobody;
3 worker_processes 1;
4
5 #error_log logs/error.log;
6 #error_log logs/error.log notice;
7 #error_log logs/error.log info;
8
9 #pid logs/nginx.pid;
10
11
12 events {
13 worker_connections 1024;
14 }
15
16
17 http {
18 include mime.types;
19 default_type application/octet-stream;
20
21 #log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
22 # ‘$status $body_bytes_sent "$http_referer" ‘
23 # ‘"$http_user_agent" "$http_x_forwarded_for"‘;
24
25 #access_log logs/access.log main;
26
27 sendfile on;
28 #tcp_nopush on;
29
30 #keepalive_timeout 0;
31 keepalive_timeout 65;
32
33 #gzip on;
34
35 server {
36 listen 80;
37 server_name localhost;
38
39 #charset koi8-r;
40
41 #access_log logs/host.access.log main;
42
43 location / {
44 root html;
45 index index.html index.htm;
46 }
47
48 #error_page 404 /404.html;
49
50 # redirect server error pages to the static page /50x.html
51 #
52 error_page 500 502 503 504 /50x.html;
53 location = /50x.html {
54 root html;
55 }
56
57 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
58 #
59 #location ~ .php$ {
60 # proxy_pass http://127.0.0.1;
61 #}
62
63 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
64 #
65 #location ~ .php$ {
66 # root html;
67 # fastcgi_pass 127.0.0.1:9000;
68 # fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 # include fastcgi_params;
71 #}
72
73 # deny access to .htaccess files, if Apache‘s document root
74 # concurs with nginx‘s one
75 #
76 #location ~ /.ht {
77 # deny all;
78 #}
79 }
80
81
82 # another virtual host using mix of IP-, name-, and port-based configuration
83 #
84 #server {
85 # listen 8000;
86 # listen somename:8080;
87 # server_name somename alias another.alias;
88
89 # location / {
90 # root html;
91 # index index.html index.htm;
92 # }
93 #}
94
95
96 # HTTPS server
97 #
98 #server {
99 # listen 443 ssl;
100 # server_name localhost;
101
102 # ssl_certificate cert.pem;
103 # ssl_certificate_key cert.key;
104
105 # ssl_session_cache shared:SSL:1m;
106 # ssl_session_timeout 5m;
107
108 # ssl_ciphers HIGH:!aNULL:!MD5;
109 # ssl_prefer_server_ciphers on;
110
111 # location / {
112 # root html;
113 # index index.html index.htm;
114 # }
115 #}
116
117 }
[ conf]#
[ conf]# ss -antl | grep 80
LISTEN 0 50 :::8080 :::
[ conf]#
[ conf]# curl localhost
curl: (7) Failed connect to localhost:80; Connection refused
[ conf]# ss -antl | grep 80
LISTEN 0 50 :::8080 :::

[ conf]#
[ conf]# systemctl stop firewalld.service
[ conf]# systemctl disable firewalld.service
[ conf]# firewall-cmd --zone=public --add-port=80/tcp --permanent
FirewallD is not running
[ conf]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[ conf]# pwd -P
/usr/local/nginx/conf
[ conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[ conf]# ss -antl | grep 80
LISTEN 0 128 :80 :
LISTEN 0 50 :::8080 :::

[ conf]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>

CentOS系列教程(四)

孟伯,20200411

交流联系:微信 1807479153 ,QQ 1807479153

相关推荐