1、安装Nginx
sudo yum install -y nginx
2、启动Nginx并设置开机自动运行
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
3、配置:在nginx.conf的http{}里添加
server {
listen 80;
listen 443 ssl;
server_name you_site;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://[宿主机IP]:8000;
}
error_page 403 404 500 502 503 504 /ErrorPage.html;
location = /ErrorPage.html {
root /root/html;
}
ssl_certificate cert/xxx.crt;
ssl_certificate_key cert/xxx.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
}
4、配置排查注意点
(1)user nginx 修改成user root(根据账号走)
(2)error_page 配置,要开启
proxy_intercept_errors on;
fastcgi_intercept_errors on;
proxy_intercept_errors on;
fastcgi_intercept_errors on;
include /etc.........
(3) root /root/html; 表示的是html放在哪个目录下,且名称是ErrorPage.html
(4) chmod -R 777 html 要给存放html文件的目录权限
(5) http://[宿主机IP]:8000; 此处ip和端口是域名解析的对应地址,以及项目启动的端口,如果是云服务器记得开放对应的端口
(6)listen 443 ssl;添加443 端口监听
(7)ssl_certificate cert/xxx.crt;
ssl_certificate_key cert/xxx.key;
在nginx.conf同一级目录下,新增目录cert,并将.crt/key文件放在其中,与nginx配置文件指定目录一致即可
网友评论