1.安裝:linux
rpm -ivh http://nginx.org/packages/centos/6/x86_64/RPMS/nginx-1.12.2-1.el6.ngx.x86_64.rpm
2.啓動nginx
service nginx startvim
3.驗證是否成功centos
curl http://127.0.0.1:80curl
4.設置開機啓動url
chkconfig nginx on
5.修改配置文件spa
修改http配置: return 307 https://本機IP地址$request_uri;(用於將http轉爲https請求,可自定義)server
修改https配置 :ssl
修改記錄文件及bug文件路徑:ci
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.key
openssl 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