- 在/etc/nginx/conf.d目录下创建test.conf文件,输入以下配置信息
server {
listen 80;
server_name helleworld.cn; #修改域名
location / {
root /var/www/html; #代理到mall文件夹中
index index.html index.htm;
}
limit_rate 128k; #限制网速为128K
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
- 配置 /etc/nginx/nginx.conf ,html里面输入以下配置信息
include /etc/nginx/conf.d/*.conf;
- 重启nginx,systemctl restart nginx
- 配置HTTPS
- 在/etc/nginx/conf.d目录下创建ssl.conf文件,输入以下配置信息
server {
listen 80; # 同时支持HTTP
listen 443 ssl; # 添加HTTPS支持
server_name helleworld.cn;
#SSL配置
ssl_certificate /root/c.crt; # 配置证书
ssl_certificate_key /root/c.key; # 配置证书私钥
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 配置SSL协议版本
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; # 配置SSL加密算法
ssl_prefer_server_ciphers on; # 优先采取服务器算法
ssl_session_cache shared:SSL:10m; # 配置共享会话缓存大小
ssl_session_timeout 10m; # 配置会话超时时间
location / {
root /var/www/html;
index index.html index.htm;
}
location /admin {
alias /usr/share/nginx/html/admin;
index index.html index.htm;
}
location /app {
alias /usr/share/nginx/html/app;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
其中的需要手动生成SSL自签名证书并开启443端口。