设为首页 收藏本站
查看: 512|回复: 0

[经验分享] linux(6.8版本最小化安装)安装nginx实战

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-7 09:29:50 | 显示全部楼层 |阅读模式


1.安装pcre:

查看是否安装过pcre:

[iyunv@iyunvClient01 ~]# rpm -qa pcrepcre-devel

pcre-7.8-6.el6.x86_64

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

[iyunv@iyunvClient01 ~]# rpm -qa pcrepcre-devel

pcre-7.8-7.el6.x86_64

pcre-devel-7.8-7.el6.x86_64

2.安装安全软件包openssl:

[iyunv@iyunvClient01 ~]# yum installopenssl-devel -y

[iyunv@iyunvClient01 ~]# 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:

[iyunv@iyunvClient01 ~]# mkdir -p/home/oldboy/tools

[iyunv@iyunvClient01 ~]# cd /home/oldboy/tools

[iyunv@iyunvClient01 tools]# wget -qhttp://nginx.org/download/nginx-1.6.3.tar.gz

[iyunv@iyunvClient01 tools]# ls nginx-1.6.3.tar.gz

nginx-1.6.3.tar.gz

[iyunv@iyunvClient01 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目录:

[iyunv@iyunvClient01 tools]# tar zxfnginx-1.6.3.tar.gz

[iyunv@iyunvClient01 tools]# cd nginx-1.6.3

查看总共文件个数:

[iyunv@iyunvClient01 nginx-1.6.3]# tree|wc-l

404

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

[root@iyunvClient01nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx--group=nginx --with-http_ssl_module --with-http_stub_status_module

                            spacer.gif

[iyunv@iyunvClient01 nginx-1.6.3]#make&& make install

添加用户:

[iyunv@iyunvClient01 nginx-1.6.3]# useradd nginx -s /sbin/nologin -M

[iyunv@iyunvClient01 nginx-1.6.3]# id nginx

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

[iyunv@iyunvClient01 tools]# ll /application/nginx-1.6.3/ -ld

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

创建软连接:

[iyunv@iyunvClient01 tools]# ln -s/application/nginx-1.6.3/ /application/nginx

[iyunv@iyunvClient01 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服务:

[iyunv@iyunvClient01 ~]# 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      

[iyunv@iyunvClient01 ~]# ss -lntup|grep nginx

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

本地测试是否部署成功:

[iyunv@iyunvClient01 ~]# 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>


wKioL1gew0PyfC3dAADfscl9QUc343.png-wh_50查看软件安装的编译参数:

[iyunv@iyunvClient01 ~]#/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

切换到安装目录并查看:

[iyunv@iyunvClient01 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核心配置文件:

[iyunv@iyunvClient01 html]# cd ..

[iyunv@iyunvClient01 nginx]# cd conf/

[iyunv@iyunvClient01 conf]# ls -lnginx.conf

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



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

[iyunv@iyunvClient01 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;

       }

    }

}

[iyunv@iyunvClient01 conf]# egrep -v"#|^$" nginx.conf.default >nginx.conf

编辑nginx.conf文件:



[iyunv@iyunvClient01 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.iyunv.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

           root   html/www;

erver {  

       listen       80;

       server_name  www.iyunv.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

       server {

       listen       80;

       server_name  www.iyunv.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

    }

  erver {

       listen       80;

       server_name  www.iyunv.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.iyunv.org;

       location / {

           root   html/www;

           index  index.html index.htm;

       }

    }

   server {

       listen       80;

       server_name  bbs.iyunv.org;

       location / {

           root   html/bbs;

           index  index.html index.htm;

       }

    }



}

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

创建目录及html页面:              

[iyunv@iyunvClient01 conf]# mkdir../html/{www,bbs}

[iyunv@iyunvClient01 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

[iyunv@iyunvClient01 conf]#

[iyunv@iyunvClient01 conf]# echo"www.iyunv.org" >../html/www/index.html

[iyunv@iyunvClient01 conf]# echo"bbs.iyunv.org" >../html/bbs/index.html

[iyunv@iyunvClient01 conf]# cat../html/{www,bbs}/index.html

www.iyunv.org

bbs.iyunv.org

检查配置是否有误:

[iyunv@iyunvClient01 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服务:

[iyunv@iyunvClient01 conf]#/application/nginx/sbin/nginx -s reload

配置host文件,测试:

[iyunv@iyunvClient01 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.iyunv.org

192.168.10.132 bbs.iyunv.org

~

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

基于端口的nginx配置:






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-296861-1-1.html 上篇帖子: Nginx+tomcat实现https访问(tomcat不配ssl证书) 下篇帖子: Nginx web服务优化
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表