准备
安装编译需要的gcc和gcc-c++
yum install -y gcc gcc-c++
安装nginx依赖pcre-devel、openssl-devel、zlib-devel
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
准备源码包并解压:
PCRE 让 Nginx 支持 Rewrite 功能。
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
进入安装包目录
[root@bogon src]# cd pcre-8.35
编译安装
[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install
查看pcre版本
[root@bogon pcre-8.35]# pcre-config --version
安装 Nginx
1、下载 Nginx
[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
进入安装包目录
[root@bogon src]# cd nginx-1.6.2
编译安装
[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install
查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/nginx/sbin/nginx -v
指定不同域名映射
修改conf目录下的nginx.conf文件
include mime.types;
default_type application/octet-stream;#这后面新加指定加载目录
include /usr/local/nginx/vhost/*.conf;
配置-http https同时使用
server {
listen 443 ssl;
#listen [::]:81 default_server ipv6only=on;
server_name test.com; # 站点域名
#ssl on;
ssl_certificate /usr/local/webserver/nginx/ssl/4319289_test.com.pem;#只需修改这俩证书地址就ok
ssl_certificate_key /usr/local/webserver/nginx/ssl/4319289_test.com.key;#只需修改这俩证书地址就ok
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
index index.html index.htm index.php;
root /usr/local/nginx/www/test_com; # 站点根目录
}
配置-强制跳转https
server {
listen 80;
listen 443 ssl;
#listen [::]:81 default_server ipv6only=on;
server_name test.com; # 站点域名
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
#ssl on;
ssl_certificate /usr/local/webserver/nginx/ssl/4319289_test.com.pem;
ssl_certificate_key /usr/local/webserver/nginx/ssl/4319289_test.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
index index.html index.htm index.php;
root /usr/local/nginx/www/test_com; # 站点根目录
}
nginx常用命令
./nginx #启动nginx
./nginx -s reopen #重启 Nginx
./nginx -s reload #重新加载配置文件
./nginx -t #检测
./nginx -s stop #停止 Nginx