美文网首页
Nginx部署

Nginx部署

作者: 白面葫芦娃92 | 来源:发表于2019-04-22 15:18 被阅读0次

首先是pcre、openssl、zlib安装,这三者的安装顺序没有影响,但一定这三个全安装好之后再安装nginx
1.安装pcre库

[root@hadoop001 local]# ll
total 72
drwxr-xr-x   6 root       root 4096 Apr 22 12:50 aegis
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 bin
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 etc
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 games
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 include
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 lib
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 lib64
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 libexec
drwxr-xr-x  15 mysqladmin dba  4096 Apr 11 20:21 mysql
drwxr-xr-x   8 root       root 4096 Apr 21  2015 nginx-1.8.0
drwxr-xr-x  22 root       root 4096 Apr 22 14:34 openssl-1.0.1j
drwxr-xr-x   7 root       root 4096 Sep 26  2014 pcre-8.36
drwxr-xr-x   5 root       root 4096 Apr 11 12:41 protobuf
drwxr-xr-x  10 root       root 4096 Apr 11 12:39 protobuf-2.5.0
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 sbin
drwxr-xr-x.  6 root       root 4096 Dec  3 11:09 share
drwxr-xr-x.  2 root       root 4096 Apr 11  2018 src
drwxr-xr-x  14 root       root 4096 Jan 16  2017 zlib-1.2.11
[root@hadoop001 local]# cd pcre-8.36/
[root@hadoop001 pcre-8.36]# ./configure
[root@hadoop001 pcre-8.36]# make && make install

2.安装zlib库

[root@hadoop001 ~]# cd /usr/local
[root@hadoop001 local]# cd zlib-1.2.11/
[root@hadoop001 zlib-1.2.11]# ./configure
[root@hadoop001 zlib-1.2.11]# make && make install

3.openssl

[root@hadoop001 local]# cd openssl-1.0.1j/
[root@hadoop001 openssl-1.0.1j]# ./config
[root@hadoop001 openssl-1.0.1j]# make && make install

4.安装nginx

[root@hadoop001 local]# cd nginx-1.8.0/
[root@hadoop001 nginx-1.8.0]# ll
total 652
drwxr-xr-x 6 root root   4096 Apr 22 14:34 auto
-rw-r--r-- 1 root root 249124 Apr 21  2015 CHANGES
-rw-r--r-- 1 root root 379021 Apr 21  2015 CHANGES.ru
drwxr-xr-x 2 root root   4096 Apr 22 14:34 conf
-rwxr-xr-x 1 root root   2478 Apr 21  2015 configure
drwxr-xr-x 4 root root   4096 Apr 22 14:34 contrib
drwxr-xr-x 2 root root   4096 Apr 22 14:34 html
-rw-r--r-- 1 root root   1397 Apr 21  2015 LICENSE
drwxr-xr-x 2 root root   4096 Apr 22 14:34 man
-rw-r--r-- 1 root root     49 Apr 21  2015 README
drwxr-xr-x 8 root root   4096 Apr 22 14:34 src
[root@hadoop001 nginx-1.8.0]# ./configure --prefix=/usr/local/nginx \
> --with-pcre=/usr/local/pcre-8.36 \
> --with-zlib=/usr/local/zlib-1.2.11
[root@hadoop001 nginx-1.8.0]# make && make install

--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36的源码路径
--with-zlib=/usr/local/zlib-1.2.11 指的是zlib-1.2.11的源码路径

5.启动nginx

[root@hadoop001 nginx-1.8.0]# cd ../nginx
[root@hadoop001 nginx]# ll
total 16
drwxr-xr-x 2 root root 4096 Apr 22 14:55 conf
drwxr-xr-x 2 root root 4096 Apr 22 14:55 html
drwxr-xr-x 2 root root 4096 Apr 22 14:55 logs
drwxr-xr-x 2 root root 4096 Apr 22 14:55 sbin
[root@hadoop001 nginx]# cd sbin
[root@hadoop001 sbin]# ll
total 3364
-rwxr-xr-x 1 root root 3444072 Apr 22 14:55 nginx
[root@hadoop001 sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

和httpd的端口号冲突了,修改nginx的端口号即可

[root@hadoop001 sbin]# cd ../conf
[root@hadoop001 conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Apr 22 14:55 fastcgi.conf
-rw-r--r-- 1 root root 1034 Apr 22 14:55 fastcgi.conf.default
-rw-r--r-- 1 root root  964 Apr 22 14:55 fastcgi_params
-rw-r--r-- 1 root root  964 Apr 22 14:55 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Apr 22 14:55 koi-utf
-rw-r--r-- 1 root root 2223 Apr 22 14:55 koi-win
-rw-r--r-- 1 root root 3957 Apr 22 14:55 mime.types
-rw-r--r-- 1 root root 3957 Apr 22 14:55 mime.types.default
-rw-r--r-- 1 root root 2656 Apr 22 14:55 nginx.conf
-rw-r--r-- 1 root root 2656 Apr 22 14:55 nginx.conf.default
-rw-r--r-- 1 root root  596 Apr 22 14:55 scgi_params
-rw-r--r-- 1 root root  596 Apr 22 14:55 scgi_params.default
-rw-r--r-- 1 root root  623 Apr 22 14:55 uwsgi_params
-rw-r--r-- 1 root root  623 Apr 22 14:55 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Apr 22 14:55 win-utf
[root@hadoop001 conf]# vi nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

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

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       880;
        server_name  hadoop001;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

[root@hadoop001 conf]# cd ../sbin
[root@hadoop001 sbin]# ./nginx
[root@hadoop001 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hadoop001 sbin]# ps -ef|grep nginx
root     28840     1  0 15:04 ?        00:00:00 nginx: master process ./nginx
nobody   28841 28840  0 15:04 ?        00:00:00 nginx: worker process
root     28877 10102  0 15:05 pts/2    00:00:00 grep --color=auto nginx
[root@hadoop001 sbin]# netstat -nlp|grep nginx
tcp        0      0 0.0.0.0:880             0.0.0.0:*               LISTEN      28840/nginx: master 
6.浏览器打开http://39.98.63.103:880/

7.查看log

[root@hadoop001 sbin]# cd ../logs
[root@hadoop001 logs]# ll
total 12
-rw-r--r-- 1 root root 428 Apr 22 15:07 access.log
-rw-r--r-- 1 root root 795 Apr 22 15:07 error.log
-rw-r--r-- 1 root root   6 Apr 22 15:04 nginx.pid
[root@hadoop001 logs]# tail -F access.log
124.127.64.30 - - [22/Apr/2019:15:07:30 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36" "-"
124.127.64.30 - - [22/Apr/2019:15:07:30 +0800] "GET /favicon.ico HTTP/1.1" 404 570 "http://39.98.63.103:880/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36" "-"

用本地windows浏览器访问一下http://39.98.63.103:880/,发现log日志新增一条

124.127.64.30 - - [22/Apr/2019:15:10:11 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36" "-"

nginx的其他命令:
nginx -s reload 重启
nginx -s stop 停止
nginx -t 测试配置文件是否正常
pkill nginx 强制关闭 也可以用kill -9 $(pgrep -f nginx)

相关文章

网友评论

      本文标题:Nginx部署

      本文链接:https://www.haomeiwen.com/subject/savygqtx.html