# 安装 & 启动
Linux下安装Nginx (opens new window)
Linux安装Nginx详细教程 (opens new window)
进入 /usr/local/nginx/sbin,执行:
./nginx
# 简易反向代理配置
修改主配置文件 /usr/local/nginx/conf/nginx.conf 中的 server{} 中的内容
# 内部转发到3000端口
location / {
proxy_pass http://127.0.0.1:3000/;
}
记得要回到/usr/local/nginx/sbin中重启:
./nginx -s reload
# 部署HTTPS访问 (Nginx)
前置工作:购买域名,完成基本HTTP访问,申请免费的DV证书并通过验证(具体参考各云服务商教程)
下载证书,上传到你的服务器(你能找到就可以)
Nginx 重新装载SSL模块
Nginx解决配置SSL证书报错 (opens new window)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
- 进入nginx目录配置nginx.conf (找不到可以 whereis nginx)
# HTTPS server
#
server {
listen 443 ssl;
server_name yourDomain.com;
ssl_certificate /root/server.pem; #你找的到就可以,注意这是绝对路径
ssl_certificate_key /root/server.key;
ssl_session_cache shared:SSL:1m; # 下面配置这些抄过去就可以
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:3000/; # 这一条是内部转发3000端口用的
}
}
# HTTP server
# 配置 HTTPS重定向~
server{
listen 80;
server_name yourDomain.com;
rewrite ^(.*)$ https://yourDomain.com;
}
- 重启nginx~