linux(6.8版本最小化安装)安装nginx实战

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux(6.8版本最小化安装)安装nginx实战相关的知识,希望对你有一定的参考价值。

1.安装pcre:

查看是否安装过pcre:

[[email protected] ~]# rpm -qa pcrepcre-devel

pcre-7.8-6.el6.x86_64

若没有则执行安装命令:[[email protected] ~]# yum install pcre-devel -y

[[email protected] ~]# rpm -qa pcrepcre-devel

pcre-7.8-7.el6.x86_64

pcre-devel-7.8-7.el6.x86_64

2.安装安全软件包openssl:

[[email protected] ~]# yum installopenssl-devel -y

[[email protected] ~]# rpm -qa opensslopenssl-devel

openssl-devel-1.0.1e-48.el6_8.1.x86_64

openssl-1.0.1e-48.el6_8.1.x86_64

3.安装nginx:

[[email protected] ~]# mkdir -p/home/oldboy/tools

[[email protected] ~]# cd /home/oldboy/tools

[[email protected] tools]# wget -qhttp://nginx.org/download/nginx-1.6.3.tar.gz

[[email protected] tools]# ls nginx-1.6.3.tar.gz

nginx-1.6.3.tar.gz

[[email protected] tools]# ls nginx-1.6.3.tar.gz -lk 

-rw-r--r-- 1 root root 787 4月   8 2015 nginx-1.6.3.tar.gz

解压并切换到nginx目录:

[[email protected] tools]# tar zxfnginx-1.6.3.tar.gz

[[email protected] tools]# cd nginx-1.6.3

查看总共文件个数:

[[email protected] nginx-1.6.3]# tree|wc-l

404

编译并安装(--prefix 编译目录)

 [[email protected]]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx--group=nginx --with-http_ssl_module --with-http_stub_status_module

                            技术分享

[[email protected] nginx-1.6.3]#make&& make install

添加用户:

[[email protected] nginx-1.6.3]# useradd nginx -s /sbin/nologin -M

[[email protected] nginx-1.6.3]# id nginx

uid=502(nginx) gid=502(nginx) 组=502(nginx)

[[email protected] tools]# ll /application/nginx-1.6.3/ -ld

drwxr-xr-x 6 root root 4096 7月  17 19:15/application/nginx-1.6.3/

创建软连接:

[[email protected] tools]# ln -s/application/nginx-1.6.3/ /application/nginx

[[email protected] tools]# ls -l/application/

总用量 8

lrwxrwxrwx 1 root root   25 7月  17 19:20 nginx ->/application/nginx-1.6.3/

drwxr-xr-x 6 root root 4096 7月  17 19:15 nginx-1.6.3

启动nginx服务:

[[email protected] ~]# ps -ef|grep nginx|grep -v grep

root    10949     1  0 19:26 ?        00:00:00 nginx: master process/application/nginx/sbin/nginx

nginx   10950 10949  0 19:26 ?        00:00:00 nginx: worker process       

[[email protected] ~]# ss -lntup|grep nginx

tcp   LISTEN     0      128                    *:80                    *:*     users:(("nginx",10949,6),("nginx",10950,6))

本地测试是否部署成功:

[[email protected] ~]# curl 127.0.0.1

<!DOCTYPE html>

<html>

<head>

<title>Welcome tonginx!</title>

<style>

   body {

       width: 35em;

       margin: 0 auto;

       font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginxweb server is successfully installed and

working. Further configuration isrequired.</p>

 

<p>For online documentation andsupport please refer to

<ahref="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<ahref="http://nginx.com/">nginx.com</a>.</p>

 

<p><em>Thank you for usingnginx.</em></p>

</body>

</html>


技术分享查看软件安装的编译参数:

[[email protected] ~]#/application/nginx/sbin/nginx -V

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat4.4.7-11) (GCC)

TLS SNI support enabled

configure arguments:--prefix=/application/nginx-1.6.3 --user=nginx --group=nginx--with-http_ssl_module --with-http_stub_status_module

切换到安装目录并查看:

[[email protected] nginx]# ls -l|grep -vtemp

总用量 36

drwxr-xr-x 2 root  root 4096 7月  17 19:15 conf

drwxr-xr-x 2 root  root 4096 7月  17 19:15 html

drwxr-xr-x 2 root  root 4096 7月  17 19:26 logs

drwxr-xr-x 2 root  root 4096 7月  17 19:15 sbin

技术分享

查看nginx核心配置文件:

[[email protected] html]# cd ..

[[email protected] nginx]# cd conf/

[[email protected] conf]# ls -lnginx.conf

-rw-r--r-- 1 root root 2656 7月  17 19:15 nginx.conf

技术分享

最小化配置基于域名的nginx的配置文件:

[[email protected]hongyaClient01 conf]# egrep -v"#|^$" nginx.conf.default

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  localhost;

       location / {

           root   html;

           index  index.html index.htm;

       }

       error_page   500 502 503 504  /50x.html;

       location = /50x.html {

           root   html;

       }

    }

}

[[email protected] conf]# egrep -v"#|^$" nginx.conf.default >nginx.conf

编辑nginx.conf文件:

 

[[email protected] conf]# vim nginx.conf

 

       location = /50x.html {

       error_page   500 502 503 504  /50x.html;

       location = /50x.html {

           root   html;

       }

           root   html/www   server {

       listen       80;

        server_name  www.hongya.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

           root   html/www;

 erver {  

       listen       80;

       server_name  www.hongya.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

       server {

       listen       80;

       server_name  www.hongya.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

    }

  erver {

       listen       80;

       server_name  www.hongya.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

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.hongya.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

    }

   server {

       listen       80;

       server_name  bbs.hongya.org;

       location / {

           root   html/bbs;

           index  index.html index.htm;

       }

    }

 

}

"nginx.conf" 32L, 566C 已写入      

创建目录及html页面:              

[[email protected] conf]# mkdir../html/{www,bbs}

[[email protected] conf]# ls -l ../html/

总用量 16

-rw-r--r-- 1 root root  537 7月  17 19:15 50x.html

drwxr-xr-x 2 root root 4096 7月  17 21:31 bbs

-rw-r--r-- 1 root root  628 7月  17 19:48 index.html

drwxr-xr-x 2 root root 4096 7月  17 21:31 www

[[email protected] conf]#

[[email protected] conf]# echo"www.hongya.org" >../html/www/index.html

[[email protected] conf]# echo"bbs.hongya.org" >../html/bbs/index.html

[[email protected] conf]# cat../html/{www,bbs}/index.html

www.hongya.org

bbs.hongya.org

检查配置是否有误:

[[email protected] conf]#/application/nginx/sbin/nginx -t

nginx: the configuration file/application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file/application/nginx-1.6.3/conf/nginx.conf test is successful

重启nginx服务:

[[email protected] conf]#/application/nginx/sbin/nginx -s reload

配置host文件,测试:

[[email protected] conf]# vim /etc/hosts

 

127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4

::1        localhost localhost.localdomain localhost6 localhost6.localdomain6

 

192.168.10.132 www.hongya.org

192.168.10.132 bbs.hongya.org

~

"/etc/hosts" 5L, 221C 已写入 

基于端口的nginx配置:

技术分享

技术分享


以上是关于linux(6.8版本最小化安装)安装nginx实战的主要内容,如果未能解决你的问题,请参考以下文章

centos 6.8 安装LNMP环境(linux+nginx+mysql+php)

最新版Oracle Linux 6.8系统的安装

mark LINUX_6.8 python_2.6.6 setup版本升级 python 2.7.9 安装 pip 临时使用国内镜像源库 指定模块版本 删除指定模块

CentOS-6.8 最详细安装教程(贴镜像文件+多图)

源码安装nginxmysql的注意事项

#私藏项目实操分享# Linux开发环境搭建CentOs7之四Web服务器Nginx安装部署