1、下载包
wget -c http://tengine.taobao.org/download/tengine-2.3.0.tar.gz
tar xf tengine-2.3.0.tar.gz -C /usr/local/src/
cd /usr/local/src/tengine-2.3.0/
2、编译安装
yum install gcc c++
yum install -y openssl-devel
yum install pcre-devel
./configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--user=nginx --group=nginx \
--with-debug --with-file-aio \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-pcre --with-pcre-jit
make
make install
3、写服务脚本
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has
the wrong
# SELinux context. This might happen when running `nginx -t` from th
e cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.targe
useradd -r -c "Nginx web server" -M -s /sbin/nologin nginx
4、测试脚本
systemctl daemon-reload
systemctl start nginx
systemctl status nginx
systemctl stop nginx
systemctl status nginx
重新启动,在浏览器
基于用户访问控制
cd /etc/nginx/conf.d/
vim auth_user.conf
server{
location / {
root html;
index index.html index.htm;
auth_basic "Restricted";
auth_basic_user_file /data/web2/webpass;
}
}
yum install -y http-tools
touch /data/web2/webpass/
htpasswd -c /data/web2/webpass tom
New password:
Re-type new password:
Adding password for user tom
[root@localhost conf.d]# systemctl restart nginx