nginx 基本使用
-
以管理员运行命令行
-
cd 到 nginx 根目录 启动
启动命令:start nginx
- 在任务管理器看到两个
说明启动了,其中一个是主进程,一个是工作进程
-
相关常用命令(nginx 根目录)
nginx -c /path/to/nginx.conf #以特定目录下的配置文件启动nginx: nginx -s reload #修改配置后重新加载生效 nginx -s reopen #重新打开日志文件 nginx -s stop #快速停止nginx,暴力停止,可能造成数据丢失 nginx -s quit #完整有序的停止nginx nginx -t #测试当前配置文件是否正确 nginx -t -c /path/to/nginx.conf #测试特定的nginx配置文件是否正确
nginx 配置 https
- 解压 nginx.zip
- 运行 setup-x86_64.exe 安装 cygwin
- 通过命令行运行 C:\cygwin64\bin 目录下的 openssl.exe
- 生成证书(管理员方式打开命令行)
# 1、首先,进入你想创建证书和私钥的目录,例如:nginx/config目录
cd D:\\dev\\nginx-1.13.12\\conf
# 2、创建服务器私钥,命令会让你输入一个口令:
openssl genrsa -des3 -out server.key 1024
# 3、创建公钥(CSR):
openssl req -new -key server.key -out server.csr
# 4、不用输入密码
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
# 5、最后标记证书使用上述私钥和公钥:
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
- 配置 nginx
- 访问
https://localhost
即可显示 nginx 目录下 html 下的 index.html 或者 index.htm
重定向
nginx 负载均衡
nginx 代理
- 操作最好在管理员权限下进行
- nginx -s [opt] opt:stop, quit, reopen, reload
- 启动 nginx: 命令行进入到解压目录
start nginx
- 查看 nginx 启动进程
tasklist /fi "imagename eq nginx.exe"
- 关闭进程
nginx -s stop