编译安装nginx

编译安装nginx:

[root@web02 ~]# id nginx 
uid=998(nginx) gid=996(nginx) groups=996(nginx)
[root@web02 ~]# mkdir -p /app

[root@web02 ~]# ll
total 1012
-rw-r--r-- 1 root root 1032345 Jun 12 20:08 nginx-1.16.0.tar.gz
[root@web02 ~]# tar xf nginx-1.16.0.tar.gz 
[root@web02 ~]# ll
total 1012
drwxr-xr-x 8 1001 1001     158 Apr 23 21:13 nginx-1.16.0
-rw-r--r-- 1 root root 1032345 Jun 12 20:08 nginx-1.16.0.tar.gz

[root@web02 ~]# yum install -y pcre pcre-devel  #支持nginx的正则
[root@web02 ~]# yum install -y openssl      #加密认证

[root@web02 ~]# ll
total 1012
drwxr-xr-x 8 1001 1001     158 Apr 23 21:13 nginx-1.16.0
-rw-r--r-- 1 root root 1032345 Jun 12 20:08 nginx-1.16.0.tar.gz
[root@web02 ~]# ll nginx-1.16.0
total 748
drwxr-xr-x 6 1001 1001    326 Jun 12 20:14 auto
-rw-r--r-- 1 1001 1001 296223 Apr 23 21:13 CHANGES
-rw-r--r-- 1 1001 1001 451813 Apr 23 21:13 CHANGES.ru
drwxr-xr-x 2 1001 1001    168 Jun 12 20:14 conf
-rwxr-xr-x 1 1001 1001   2502 Apr 23 21:12 configure  #可执行的文件
drwxr-xr-x 4 1001 1001     72 Jun 12 20:14 contrib
drwxr-xr-x 2 1001 1001     40 Jun 12 20:14 html
-rw-r--r-- 1 1001 1001   1397 Apr 23 21:12 LICENSE
drwxr-xr-x 2 1001 1001     21 Jun 12 20:14 man
-rw-r--r-- 1 1001 1001     49 Apr 23 21:12 README
drwxr-xr-x 9 1001 1001     91 Jun 12 20:14 src

[root@web02 ~]# ./configure --user=nginx --group=nginx --prefix=/app/nginx-1.16.0/ --with-http_stub_status_module --with-http_ssl_module --with-pcre

[root@web02 ~]#make&&make install

[root@web02 app]# cd /app
[root@web02 app]# ll 
total 0
drwxr-xr-x 6 root root 54 Jun 12 20:26 nginx-1.16.0
[root@web02 app]# ll nginx-1.16.0/
total 0
drwxr-xr-x 2 root root 333 Jun 12 20:26 conf
drwxr-xr-x 2 root root  40 Jun 12 20:26 html
drwxr-xr-x 2 root root   6 Jun 12 20:26 logs
drwxr-xr-x 2 root root  36 Jun 12 20:27 sbin

[root@web02 app]# ln -s /app/nginx-1.16.0/ /app/nginx
[root@web02 app]# ll 
total 0
lrwxrwxrwx 1 root root 18 Jun 12 20:37 nginx -> /app/nginx-1.16.0/
drwxr-xr-x 6 root root 54 Jun 12 20:26 nginx-1.16.0

[root@web02 html]# vim /app/nginx/conf/nginx.conf
worker_processes  1;
events {
worker_connections  1024;
}
http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
                listen       80;
                server_name  www.oldboy.com;
                location / {
                        root   html/www;
                        index  index.html index.htm;
                }
        }
        server {
                listen       80;
                server_name  blog.oldboy.com;
                location / {
                        root   html/blog;
                        index  index.html index.htm;
                }
        }
        server {
                listen       80;
                server_name  bbs.oldboy.com;
                location / {
                        root   html/bbs;
                        index  index.html index.htm;
                }
        }
}

[root@web02 html]# cd /app/nginx/html/
[root@web02 html]# ll
total 8
-rw-r--r-- 1 root root 494 Jun 12 20:26 50x.html
-rw-r--r-- 1 root root 612 Jun 12 20:26 index.html
[root@web02 html]# mkdir /app/nginx/html/www
[root@web02 html]# mkdir /app/nginx/html/blog
[root@web02 html]# mkdir /app/nginx/html/bbs
[root@web02 html]# ll
total 8
-rw-r--r-- 1 root root 494 Jun 12 20:26 50x.html
drwxr-xr-x 2 root root   6 Jun 12 20:45 bbs
drwxr-xr-x 2 root root   6 Jun 12 20:45 blog
-rw-r--r-- 1 root root 612 Jun 12 20:26 index.html
drwxr-xr-x 2 root root   6 Jun 12 20:44 www

[root@web02 html]# echo 'www.oldboy.com' >/app/nginx/html/www/index.html
[root@web02 html]# echo 'blog.oldboy.com' >/app/nginx/html/blog/index.html
[root@web02 html]# echo 'bbs.oldboy.com' >/app/nginx/html/bbs/index.html
[root@web02 html]#
[root@web02 html]# cat /app/nginx/html/*/index.html
bbs.oldboy.com
blog.oldboy.com
www.oldboy.com

[root@web02 html]# vim /etc/hosts
172.16.1.8      web02 www.oldboy.com blog.oldboy.com bbs.oldboy.com

windows域名解析:

image
[root@web02 html]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.0//conf/nginx.conf test is successful
[root@web02 html]# /app/nginx/sbin/nginx   #启动
[root@web02 html]# ps -ef |grep nginx  #查看进程

检查语法
    /app/nginx/sbin/nginx -t
启动
    /app/nginx/sbin/nginx
重启
    ps -ef |grep nginx -s reload
关闭
    /app/nginx/sbin/nginx -s stop

你可能感兴趣的:(编译安装nginx)