本文主要给出各场景下 nginx 的配置文件示例, 虽然精简, 可是都可以运行.node
经过 nginx -t
查看本机 nginx 配置文件是哪一个, 将下面示例进行替换, 而后 nginx -s reload
重启 nginx 便可.nginx
note: 覆盖原有的 nginx 配置文件以前, 能够对原来的配置文件进行备份
cp nginx.conf nginx.conf.bak
events { worker_connections 1024; } http { server { listen 8080; location / { root /data/www; # 替换为静态文件目录 } } }
events { worker_connections 1024; } http { server { listen 8081; location / { root /data/www2; # 端口 1 静态文件目录 } } server { listen 8080; location / { root /data/www; # 端口 2 静态文件目录 } } }
events { worker_connections 1024; } http { server { listen 8080; location / { root /data/www; } } server { listen 8081; # 代理端口 location / { proxy_pass http://localhost:8080; # 代理到什么路径 } } }
若是是自测 https, 能够生成自签名证书bash
cd ~/cert openssl genrsa 2048 > host.key chmod 400 host.key openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.cert
配置文件为服务器
events { worker_connections 1024; } http { server { listen 80; listen 443 ssl; ssl_certificate /root/cert/host.cert; ssl_certificate_key /root/cert/host.key; location / { root /data/www; } } }
(若有错误或不一样的看法, 望不吝指出, 愿共同进步!)代理