Linux环境编译安装Nginx

1、安装编译工具

yum -y install make zlib zlib-devel gcc gcc-c++ libtool  openssl openssl-devel pcre pcre-devel ncurses-devel perl

2、创建用户

groupadd www
useradd -g www www -M -s /sbin/nologin
# -M参数表示不添加用户家目录,-s参数表示指定shell类型

3、安装Nginx

下载地址:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0

./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_sub_module

#  –with-http_stub_status_module 启用 Nginx 的 NginxStatus 功能

make && make install

# 软链
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

nginx -v   # 查看版本

netstat -ano|grep 80  # 检查80端口

nginx      # 启动
nginx -t   # 检查配置

查看Nginx所在网址
http://127.0.0.1

Welcome to nginx!

4、常用操作

nginx -s reload            # 重新载入配置文件
nginx -s reopen            # 重启 Nginx
nginx -s stop              # 停止 Nginx

开机自启

vi /etc/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
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 quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

参考
Nginx安装及配置详细教程
Nginx 安装配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值