1、首先检查是否安装了pcre,openssl,gzip等
[root@iZ286yyopd3Z nginx]# rpm -qa | grep "pcre"
pcre-8.32-15.el7.x86_64pcre-devel-8.32-15.el7.x86_64
[root@iZ286yyopd3Z nginx]# rpm -qa | grep "openssl"
openssl-1.0.1e-34.el7_0.7.x86_64
openssl-libs-1.0.1e-34.el7_0.7.x86_64
gzip-1.5-7.el7.x86_64
如上显示则为已安装,否则使用yum进行安装。命令分别是:
yum install pcre*
yum install openssl*
yum install zlib
yum install zlib-devel
2、下载ngix
[root@iZ286yyopd3Z nginx]# wget http://nginx.org/download/nginx-1.9.9.tar.gz
--2017-07-15 16:16:05-- http://nginx.org/download/nginx-1.9.9.tar.gz
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 887908 (867K) [application/octet-stream]
Saving to: ‘nginx-1.9.9.tar.gz’
100%[=================================================================================================================================>] 887,908 73.0KB/s in 14s
2017-07-15 16:16:19 (63.6 KB/s) - ‘nginx-1.9.9.tar.gz’ saved [887908/887908]
3、解压
root@iZ286yyopd3Z nginx]# tar -zxvf nginx-1.9.9.tar.gz
4、安装
[root@iZ286yyopd3Z nginx-1.9.9]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module && make && make install
5、启动
安装默认在usr/local/nginx 在该目录输入
[root@iZ286yyopd3Z nginx]# ./sbin/nginx
重启 ./sbin/nginx -s reload
查看
[root@iZ286yyopd3Z nginx]# ps -ef | grep nginx
root 16200 1 0 17:31 ? 00:00:00 nginx: master process ./sbin/nginx
nobody 16201 16200 0 17:31 ? 00:00:00 nginx: worker process
root 25771 24255 0 17:32 pts/1 00:00:00 grep --color=auto nginx
此时输入网址,可以在浏览器中看到
6、配置https
找到nginx.conf文件,默认在usr/local/nginx/conf下,我的配置为
server {
listen 80;
#server_name localhost;
listen 443 ssl;
server_name wangchunze.top;
ssl on;
ssl_certificate /etc/nginx/214197219570764.pem;
ssl_certificate_key /etc/nginx/214197219570764.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;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
ssl_certificate /etc/nginx/214197219570764.pem;
ssl_certificate_key /etc/nginx/214197219570764.key;
为证书和key,从阿里云购买后下载并上传到服务器即可。
7、多端口访问配置
location /xxx{
proxy_pass http://wangchunze.top:30332/xxx;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这样当访问https://wangchunze.top/xxx的时候,请求会自动转发到http://wangchunze.top:30332/xxx