nginx安装
1.
安装
Nginx
所需的
pcre
库
yum install -y pcre-devel
2.
安装
Nginx
( 1 )
检查并安装
Nginx
基础依赖包
pcre-devel
、
openssl-devel
# rpm -qa | egrep 'pcre-devel | openssl-devel'
( 2 )
安装
openssl-devel
yum install -y openssl-devel
( 3 )
开始安装
Nginx
useradd nginx -s /sbin/nologin -M ./configure --user=nginx group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module
# 编译并安装
make && make install
( 4)
为
nginx
提供
SysV init
脚本
# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/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
5.启动服务
systemctl start nginx
配置基于域名的虚拟主机
在/etc/nginx/conf.d下创建xxx.conf,内容为:
server{
listen 80;
server_name www.jianwen.com;
location / {
root /abc;
index index.html index.htm;
}
}
创建/abc文件夹,在此文件夹下创建并编写index.html。
配置nginx基于用户和地址的访问控制。
基于主机
在配置文件中添加 allow 允许某些主机,deny 拒绝某些主机。
基于用户
在server下添加
auth_basic "nginx access test!";
auth_basic_user_file /etc/nginx/conf.d/passwd;
nginx的rewrite
location / {
root html;
index index.html index.htm;
if (!-f $request_filename) {
rewrite /.* /err.html permanent; (permanent表示永久的重定向到这个页面)
}