1.安装:
rpm -ivh http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.12.2-1.el6.ngx.x86_64.rpm
2.启动
service nginx start
3.验证是否成功
curl http://127.0.0.1:80
4.设置开机启动
chkconfig nginx on
5.修改配置文件
修改http配置: return 307 https://本机IP地址$request_uri;(用于将http转为https请求,可自定义)
修改https配置 :
修改记录文件及bug文件路径:
access_log /var/log/nginx/access.log;(记录文件)
error_log /var/log/nginx/error.log;(错误文件)静态文件配置:
location / {
root /mnt/ox_total_server/wwwroot/; }动态请求配置:
location ^~ /req/ {
proxy_pass http://127.0.0.1:6021; proxy_set_header Host $host:6021; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }6.创建不受信任的SSL Key
cd /
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.keyopenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
7.修改https配置
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;如遇报错可查看
/var/log/nginx/access.log;
/var/log/nginx/error.log;
8.如遇到403 forbidden (13: Permission denied)报错
vim /etc/selinux/config
将SELINUX=enforcing 修改为 SELINUX=disabled 状态。
重启 reboot
或临时关闭selinux setenforce 0