安装基础依赖
yum-y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum-y install wget httpd-tools
配置nginx的yum源
cd /etc/yum.repos.d vim nginx.repo
写入如下配置
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
查看nginx是否可以找到
yum list | grep nginx
安装nginx
默认安装稳定版
yum -y install nginx
nginx的配置文件在/etc/nginx/nginx.conf
自定义的配置文件放在/etc/nginx/conf.d
项目文件存放在/usr/share/nginx/html/
日志文件存放在/var/log/nginx/
还有一些其他的安装文件都在/etc/nginx
设置开机自启
首先修改/etc/rc.d/rc.local文件,添加如下内容:
执行以下命令,使/etc/rc.d/rc.local变成可执行文件。
chmod +x /etc/rc.d/rc.local
安装完成进入安装目录中:
cd /usr/local/nginx/sbin
启动、关闭、重启命令:
./nginx 启动
./nginx -s stop 关闭
./nginx -s reload 重启
开启HTTPS
修改配置文件 vi /etc/nginx/conf.d/default.conf
server {
listen 443; (把80改成443)
在server_name localhost;下面添加
ssl on;
ssl_certificate /etc/nginx/1_bipt.edu.cn_bundle.crt; (证书的绝对路径)
ssl_certificate_key /etc/nginx/2_bipt.edu.cn.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;
(下面的不要动)
最后添加
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri;
}
(HTTP重定向至HTTPS)
配置端口映射
修改配置文件 vi /etc/nginx/conf.d/default.conf
把以下字段
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
改成想要映射的地址,如:
location / {
proxy_pass http://210.31.45.194:8088/StuWorkO;
}
配置完成后,检查一下nginx配置文件是否可用,有successful表示可用。
$ nginx -t // 检查nginx配置文件
配置正确后,重新加载配置文件使配置生效:
$ nginx -s reload // 使配置生效
检查是否成功:
curl --insecure https://localhost