Centos Nginx 源码编译安装

Nginx 安装

1、执行命令 cd /usr/local

2、安装  gcc 和 gcc-c++

     yum install gcc

     yum install -y gcc gcc-c++

3、安装pcre 库

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

cd pcre-8.39/
    ./configure
    make && make install

4、安装zlib

         wget http://zlib.net/zlib-1.2.8.tar.gz

          cd zlib-1.2.8/
      ./configure
      make && make install

5、安装openSSL

wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz

cd openssl-1.0.1t
      ./config
      make && make install

(如果说缺少 perl  则安装perl 

yum install -y perl

Yum install -y cpan ) 

6、安装nginx

下载 wget http://nginx.org/download/nginx-1.10.1.tar.gz

解压

tar -xzvf nginx-1.10.1.tar.gz

mv nginx-1.10.1.tar.gz nginx

./configure
make && make install

7、启动nginx

启动  /usr/local/nginx/sbin/nginx

   或者在后加  -c /usr/local/nginx/conf/nginx.conf

(-c制定配置文件的路径,不加-nginx会自动加载默认路径的配置文件)

停止 /usr/local/nginx/sbin/nginx -s stop

重新加载配置 /usr/local/nginx/sbin/nginx -s reload

配置文件检测/usr/local/nginx/sbin/nginx -t

 

8、开机自动启动及快捷方式

   在/usr/lib/systemd/system下创建nginx.service文件,内容如下:

[Unit]

Description=nginx -web server

Documentation=http://nginx.org/en/docs/

After=network.target

 

[Service]

Type=forking

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s stop

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

或者

[Unit]

Description=nginx -web server

Documentation=http://nginx.org/en/docs/

After=network.target

 

[Service]

Type=forking

 

Environment=PIDFile=/usr/local/nginx/nginx.pid

 

ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

 

 

说明

[Unit]

Description : 服务的简单描述
Documentation : 服务文档

After= : 依赖,仅当依赖的服务启动之后再启动自定义的服务单元

[Service]

Type : 启动类型simple、forking、oneshot、notify、dbus

ExecStartPre :启动前要做什么,上文中是测试配置文件 -t  
ExecStart:启动 
ExecReload:重载 
ExecStop:停止 

PrivateTmp:True表示给服务分配独立的临时空间

[Install]

WantedBy:服务安装的用户模式,multi-user.target ,指使用这个服务的目录是多用户

 

再执行

systemctl enable nginx.service

就会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。

启动 systemctl start nginx.service

停止systemctl stop nginx.service

重载 systemctl restart nginx.service

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值