Nginx安装
1.下载相关组件yum install -y gcc gcc-c++ #安装C/C++编译器yum -y install gd-devel geoip-devel perl-ExtUtils-Embedwget wget wget https://www.openssl.org/source/openssl-1.0.2h.tar.gzwget wget gz 2.顺次解压安装zlib/pcre/openssl/nginx并安装zlib/pcre这些库文件直接 ./configure &&make &&make install tar xf openssl-1.0.2h.tar.gz -C /rootcd /root/openssl-1.0.2h
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make
make install
cd /root/nginx-1.6.2./configure --add-module=/root/ngx_cache_purge-2.1 --prefix=/etc/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=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-http_degradation_module --with-http_perl_module --with-ld-opt=-Wl,-E --with-mail_ssl_module --with-http_image_filter_module --with-http_geoip_module --with-http_ssl_module --with-openssl=/root/openssl-1.0.2h
makemake install
错误信息:
/usr/local/nginx/sbin/nginx: error whileloading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法:
cd /lib64
ln -s libpcre.so.0.0.1 libpcre.so.1
启动方法:
启动:nginx
停止:nginx -s stop
重载:nginx reload
3.虚拟主机
基于域名的虚拟主机:
server {
listen 80;
server_name www1.zyg.com;
root /etc/nginx/www1; #创建目录
index index.html;
}
server {
listen 80;
server_name www2.zyg.com;
root /etc/nginx/www2;
index index.html;
}
基于IP的虚拟主机:
server {
listen 192.168.122.11:80;
root /etc/nginx/www1;
index index.html;
}
server {
listen 2.2.2.1:80;
root /etc/nginx/www2;
index index.html;
}
基于端口的虚拟主机:
server {
listen 8001;
root /etc/nginx/www1;
index index.html;
}
server {
listen 8002;
root /etc/nginx/www2;
index index.html;
}
4.访问控制
server {
listen 8001;
root www1;
index index.html;
auth_basic "test"; #一个提示
auth_basic_user_file /usr/local/nginx/passwd.db;
}
server {
listen 8002;
root www2;
index index.html;
allow 192.168.122.0/24;
deny all;
}
[root@node1 nginx]# htpasswd -c /usr/local/nginx/passwd.db power #给power设置密码
5.平滑升级