简单配置Nginx 指向本地端口,并开启SSL
简单配置Nginx 指向本地端口,并开启SSL,
如果要开启SSL,必须使用域名去申请SSL key,一般是两个文件,一般是要收费的。
# 在/etc/nginx/nginx.conf 的文件中有下面一句,意思是调用 /etc/nginx/conf.d/
# 下面的配置文件,加载到主配置文件(nginx.conf)中。
include /etc/nginx/conf.d/*.conf;
# 到/etc/nginx/conf.d 目录中,创建一个 default.conf文件,加入如下代码
# 配置本地端口
server {
listen 80 default_server;
server_name _;
location / {
# 增加代理指向本地端口
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# 开启SSL
server {
listen 443 ssl;
# 指定SSL 可访问的网站
server_name cni.emcoo.com www.cni.emcoo.com;
ssl_certificate /etc/nginx/ssl/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
# 指定 SSL 指向本地端口
proxy_pass http://localhost:3000/;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}