当前位置:首页 > 服务器技术 > nginx

Nginx的web功能安装

[root@web01 ~]# yum install pcre pcre-devel -y (下载依赖库)

[root@web01 ~]# yum install openssl-devel -y https 加密服务会用到)

[root@web01 ~]# rpm -qa pcre pcre-devel (检查)

pcre-devel-7.8-7.el6.x86_64

pcre-7.8-7.el6.x86_64

[root@web01 ~]# rpm -qa openssl openssl-devel

openssl-devel-1.0.1e-42.el6.x86_64

openssl-1.0.1e-42.el6.x86_64

useradd nginx -M -s /sbin/nologin (建立虚拟用户, -M 不创建家目录,不允许登录)

id nginx (检查虚拟用户)

mkdir -p /application/tools (创建目录)

cd /application/tools (切换目录)

rz (上传压缩包,上传到的目录为当前所在目录)

tar xf nginx-1.6.3.tar.gz  (解压)

cd nginx-1.6.3

./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module (初始化数据库)

make && make install (编译并安装)

echo $? (检验编译是否成功,输出为 0 表示正常, 1 为不正常)

ln -s /application/nginx-1.6.3/ /application/nginx (创建软连接,不要是用 rm -rf 删除软连接,会把软连接下面的目录删除的)

[root@web01 ~]# /application/nginx/sbin/nginx -h (帮助文件)

nginx version: nginx/1.6.3

Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

 

Options:

  -?,-h         : this help

  -v            : show version and exit

  -V            : show version and configure options then exit

  -t            : test configuration and exit

  -q            : suppress non-error messages during configuration testing

  -s signal     : send signal to a master process: stop, quit, reopen, reload

  -p prefix     : set prefix path (default: /application/nginx-1.6.3/)

  -c filename   : set configuration file (default: conf/nginx.conf)

  -g directives : set global directives out of configuration file

[root@web01 ~]# /application/nginx/sbin/nginx -V (显示编译参数)

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (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

[root@web01 ~]# cd /application/nginx/conf/ (打开配置文件所在目录)

egrep -v "#|^$" nginx.conf.default >nginx.conf (去掉杂项, nginx.conf.default 文件为 nginx 默认配置文件)

[root@web01 conf]# vim nginx.conf d+G 为全部删除光标以下内容)

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

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

    }

}

"nginx.conf" 35L, 764C 已写入

mkdir -p ../html/{www,blog,bbs} (创建站点目录文件)

for n in www bbs blog;do echo "$n.etiantian.org" > ../html/$n/index.html;done (创建主页并写入内容)

C:WindowsSystem32driversetchosts (物理机 hosts 添加下面解析)

10.0.0.8 www.etiantian.org etiantian.org blog.etiantian.org bbs.etiantian.org

以下为简化主配置文件

[root@web01 conf]# mkdir /application/nginx/conf/extra (建立 extra 目录)

[root@web01 conf]# cat -n nginx.conf (查看行数)

     1  worker_processes  1;

     2  events {

     3      worker_connections  1024;

     4  }

     5  http {

     6      include       mime.types;

     7      default_type  application/octet-stream;

     8      sendfile        on;

     9      keepalive_timeout  65;

    10      server {

    11          listen       80;

    12          server_name  www.etiantian.org;

    13          location / {

    14              root   html/www;

    15              index  index.html index.htm;

    16          }

    17      }

    18      server {

    19          listen       80;

    20          server_name  bbs.etiantian.org;

    21          location / {

    22              root   html/bbs;

    23              index  index.html index.htm;

    24          }

    25      }

    26      server {

    27          listen       80;

    28          server_name  blog.etiantian.org;

    29          location / {

    30              root   html/blog;

    31              index  index.html index.htm;

    32          }

    33      }

    34  }

    35

[root@web01 conf]# sed -n ‘10,17p‘ nginx.conf >extra/www.conf (追加并创建各自站点配置文件)

[root@web01 conf]# cat extra/www.conf (检查配置文件)

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# sed -n ‘18,25p‘ nginx.conf >extra/bbs.conf

[root@web01 conf]# cat extra/bbs.conf

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# sed -n ‘26,33p‘ nginx.conf >extra/blog.conf

[root@web01 conf]# cat extra/blog.conf

    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

    }

[root@web01 conf]# vim nginx.conf (简化主配置文件)

worker_processes  1;

error_log logs/error.log error; (指定错误日志,相对路径为 nginx 安装目录,具体为 /application/nginx/logs/error.log

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘ (日志文件)

                      ‘$status $body_bytes_sent "$http_referer" ‘

                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    #nginx vhosts config (各站点配置添加)

    include extra/www.conf;

    include extra/bbs.conf;

    include extra/blog.conf;

    include extra/status.conf; (检查模块)

}

~                                                                                                             

~                                                                                                             

[root@web01 conf]# cat >>/application/nginx/conf/extra/status.conf<<EOF (添加检查模块文件)

##status

server{

       listen       80;

       server_name       status.etiantian.org;

       location / {

         stub_status on;

         access_log off;

         }

    }

EOF

[root@web01 conf]# vim extra/www.conf

 

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

        access_log logs/access_www.log main; (在单独标签中添加日志文件,好区分)

    }

[root@web01 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

[root@web01 conf]# /application/nginx/sbin/nginx -s reload (重启服务)

[root@web01 conf]# netstat -lntup|grep nginx (检查服务是否运行)

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      14049/nginx        

[root@web01 html]# vim /etc/rc.local (开机自启动)

 

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don‘t

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

/etc/init.d/rpcbind start

/application/nginx/sbin/nginx

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

"/etc/rc.local" 11L, 404C 已写入                                                              

技术分享650) this.width=650;" src="/upload/getfiles/default/2022/11/11/20221111014836418.jpg" title="按天轮询.png" />

按天轮询切割脚本,需要放入 crontab 中做定时任务

/bin/date +%F -d -1day

本文出自 “DNA种子” 博客,请务必保留此出处http://whyseed.blog.51cto.com/10827449/1718583

原文:http://whyseed.blog.51cto.com/10827449/1718583


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!