CentOS系列笔记(三)

安装部署并配置 Nginx 1.16.1

Deploy Nginx 1.16.1

1st installing depends

[googlebigtable@bogon ~]$ su root
Password:
[root@bogon googlebigtable]# yum -y install gcc gcc-c++ autoconf automake libtool make cmake zlib zlib-devel openssl openssl-devel pcre pcre-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

  • base: mirror.bit.edu.cn
  • extras: mirrors.cqu.edu.cn
  • updates: mirror.bit.edu.cn
    .................................................................................................................................................
    Dependency Updated:
    cpp.x86_64 0:4.8.5-39.el7 e2fsprogs.x86_64 0:1.42.9-16.el7 e2fsprogs-libs.x86_64 0:1.42.9-16.el7
    gcc-gfortran.x86_64 0:4.8.5-39.el7 krb5-libs.x86_64 0:1.15.1-37.el7_7.2 krb5-workstation.x86_64 0:1.15.1-37.el7_7.2
    libcom_err.x86_64 0:1.42.9-16.el7 libgcc.x86_64 0:4.8.5-39.el7 libgfortran.x86_64 0:4.8.5-39.el7
    libgomp.x86_64 0:4.8.5-39.el7 libkadm5.x86_64 0:1.15.1-37.el7_7.2 libquadmath.x86_64 0:4.8.5-39.el7
    libquadmath-devel.x86_64 0:4.8.5-39.el7 libss.x86_64 0:1.42.9-16.el7 libstdc++.x86_64 0:4.8.5-39.el7
    libstdc++-devel.x86_64 0:4.8.5-39.el7 openssl-libs.x86_64 1:1.0.2k-19.el7
    Complete!
    [root@bogon googlebigtable]#
    [root@bogon googlebigtable]# cd /home/googlebigtable/Downloads/
    [root@bogon Downloads]# ls -F
    manifest.txt run_upgrader.sh VMwareTools-10.2.5-8068393.tar.gz vmware-tools-upgrader-32 vmware-tools-upgrader-64
    [root@bogon Downloads]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
    --2020-04-13 02:29:59-- http://nginx.org/download/nginx-1.16.1.tar.gz
    Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
    Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1032630 (1008K) [application/octet-stream]
    Saving to: ‘nginx-1.16.1.tar.gz’
    100%[===========================================================================================================>] 1,032,630 5.80KB/s in 2m 18s
    2020-04-13 02:32:19 (7.30 KB/s) - ‘nginx-1.16.1.tar.gz’ saved [1032630/1032630]
    [root@bogon Downloads]#
    [root@bogon Downloads]# ls -F
    manifest.txt nginx-1.16.1.tar.gz run_upgrader.sh VMwareTools-10.2.5-8068393.tar.gz vmware-tools-upgrader-32 vmware-tools-upgrader-64
    [root@bogon Downloads]# tar -xzvf nginx-1.16.1.tar.gz -C /usr/local/
    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/name
    nginx-1.16.1/auto/cc/owc
    nginx-1.16.1/auto/cc/sunc
    [root@bogon Downloads]#
    [root@bogon Downloads]# cd /usr/local/
    [root@bogon local]# ls -F
    bin/ etc/ games/ include/ lib/ lib64/ libexec/ mysql/ nginx-1.16.1/ sbin/ share/ src/
    [root@bogon local]# mv nginx-1.16.1/ nginx
    [root@bogon local]# ls -F
    bin/ etc/ games/ include/ lib/ lib64/ libexec/ mysql/ nginx/ sbin/ share/ src/
    [root@bogon local]# mv nginx/ nginxsrc
    [root@bogon local]# ls -F
    bin/ etc/ games/ include/ lib/ lib64/ libexec/ mysql/ nginxsrc/ sbin/ share/ src/
    [root@bogon local]# mkdir -pv /usr/local/nginx/
    mkdir: created directory ‘/usr/local/nginx/’
    [root@bogon local]# mkdir -v nginx
    mkdir: cannot create directory ‘nginx’: File exists
    [root@bogon local]# ls
    bin etc games include lib lib64 libexec mysql nginx nginxsrc sbin share src
    [root@bogon local]# cd nginxsrc/
    [root@bogon nginxsrc]# ls -F
    auto/ CHANGES CHANGES.ru conf/ configure* contrib/ html/ LICENSE man/ README src/
    [root@bogon nginxsrc]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
    checking for OS
  • Linux 3.10.0-957.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-39) (GCC)
    checking for gcc -pipe switch ... found
    checking for -Wl,-E switch ... found
    checking for gcc builtin atomic operations ... Found
    .....................................................................................................................................
    checking for zlib library ... found
    creating objs/Makefile

Configuration summary

  • using system PCRE library
  • using system OpenSSL library
  • using system zlib library

    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx modules path: "/usr/local/nginx/modules"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# make
    make -f objs/Makefile
    make[1]: Entering directory /usr/local/nginxsrc'<br/>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 \<br/>-o objs/src/core/nginx.o \<br/>src/core/nginx.c<br/>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 \<br/>-o objs/src/core/ngx_log.o \<br/>src/core/ngx_log.c<br/>.....................................................................................................................................<br/>objs/src/http/modules/ngx_http_upstream_zone_module.o \<br/>objs/ngx_modules.o \<br/>-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \<br/>-Wl,-E<br/>sed -e "s|%%PREFIX%%|/usr/local/nginx|" \<br/>-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \<br/>-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \<br/>-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \<br/>&lt; man/nginx.8 &gt; objs/nginx.8<br/>make[1]: Leaving directory/usr/local/nginxsrc'
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# make install
    make -f objs/Makefile install
    make[1]: Entering directory /usr/local/nginxsrc'<br/>test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'<br/>test -d '/usr/local/nginx/sbin' \<br/>|| mkdir -p '/usr/local/nginx/sbin'<br/>.....................................................................................................................................<br/>test -d '/usr/local/nginx/logs' \<br/>|| mkdir -p '/usr/local/nginx/logs'<br/>make[1]: Leaving directory/usr/local/nginxsrc'
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# pwd -P
    /usr/local/nginxsrc
    [root@bogon nginxsrc]# cat >/etc/profile.d/nginx.sh<<EOF

    export NGX_HOME=/usr/local/nginx
    export PATH=\$NGX_HOME/sbin/:\$PATH
    EOF
    [root@bogon nginxsrc]# cat -n /etc/profile.d/nginx.sh
    1 export NGX_HOME=/usr/local/nginx
    2 export PATH=$NGX_HOME/sbin/:$PATH
    [root@bogon nginxsrc]# source /etc/profile
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# echo '/usr/local/nginx/sbin/nginx' >>/etc/rc.d/rc.local
    [root@bogon nginxsrc]# chmod +x /etc/rc.d/rc.local
    [root@bogon nginxsrc]# cat -n /etc/rc.d/rc.local
    1 #!/bin/bash
    2 # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
    3 #
    4 # It is highly advisable to create own systemd services or udev rules
    5 # to run scripts during boot instead of using this file.
    6 #
    7 # In contrast to previous versions due to parallel execution during boot
    8 # this script will NOT be run after all other services.
    9 #
    10 # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
    11 # that this script will be executed during boot.
    12
    13 touch /var/lock/subsys/local
    14 /usr/local/nginx/sbin/nginx
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# /usr/local/nginx/sbin/nginx -v
    nginx version: nginx/1.16.1
    [root@bogon nginxsrc]# /usr/local/nginx/sbin/nginx
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# ss -antl | grep 80
    LISTEN 0 128 :80 :
    LISTEN 0 80 :::3306 :::
    [root@bogon nginxsrc]# netstat -apn | grep 80
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28577/nginx: master
    tcp 0 0 192.168.237.128:41380 104.114.76.163:80 TIME_WAIT -
    tcp 0 0 192.168.237.128:54888 117.18.237.29:80 ESTABLISHED 28157/firefox
    tcp 0 0 192.168.237.128:54892 117.18.237.29:80 ESTABLISHED 28157/firefox
    ...........................................................................................................................................
    unix 3 [ ] STREAM CONNECTED 80088 22742/gsd-rfkill
    unix 3 [ ] STREAM CONNECTED 106806 28353/firefox
    [root@bogon nginxsrc]#
    [root@bogon nginxsrc]# /usr/local/nginx/sbin/nginx -s reload
    [root@bogon nginxsrc]# firewall-cmd --list-ports

[root@bogon nginxsrc]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@bogon nginxsrc]# firewall-cmd --reload
success
[root@bogon nginxsrc]# firewall-cmd --list-ports
80/tcp
[root@bogon nginxsrc]#
[root@bogon nginxsrc]# ls -F /usr/local/nginx/conf/
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
[root@bogon nginxsrc]# cat -n /usr/local/nginx/conf/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 }
[root@bogon nginxsrc]#

孟伯,20200411

交流联系:微信 1807479153 ,QQ 1807479153

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值