Windows 下 Nginx 安装与配置
一, 下载
过程省略
二, 配置
首先进入 nginx 安装目录 (nginx.exe 同级), 编辑 conf/nginx.conf 文件
- gzip on; #开启 gzip
- server_tokens off; ## 隐藏 nginx 版本号
- server {
- listen 8888;
- server_name localhost;
- charset utf-8;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html/dist/;
- index index.html index.htm;
- }
- location /oms {
- proxy_pass http:ip:port; #目标服务器
- # proxy_set_header Host $host;
- # proxy_set_header X-Real-IP $remote_addr;
- # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- # proxy_set_header X-Forwarded-Proto $scheme;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
三, 常规启动:
这里可以先不采用此方式, 稍后介绍设置开机自启, 将 nginx 纳入系统服务后, 通过系统命令管理
start nginx 启动
nginx -s stop 快速停止 nginx
nginx -s quit 完整有序的停止 nginx
nginx -s reopen 重新打开日志文件
nginx -s reload 重新加载配置
四, 设置开机自启:
推荐使用 Windows Service Wrapper https://github.com/kohsuke/winsw/ 工具来安装自启动服务:
1. 下载 WinSW.NET4.exe;(如果服务器未安装. NET Framework 4.0, 请下载 WinSW.NET2.exe)
2. 将 WinSW.NET4.exe 拷贝到 nginx.exe 相同目录下, 并重命名为 nginxd.exe;
3. 在 nginxd.exe 相同目录下新建一个 nginxd.xml 的配置文件, 内容如下:
- <?xml version="1.0" encoding="UTF-8" ?>
- <service>
- <id>nginx</id>
- <name>nginx</name>
- <description>nginx</description>
- <executable>D:\softs\nginx-1.14.0\nginx.exe</executable>
- <startargument>-p</startargument>
- <startargument>D:\softs\nginx-1.14.0</startargument>
- <logpath>D:\softs\nginx-1.14.0/logs</logpath>
- <logmode>roll</logmode>
- <stopexecutable>D:\softs\nginx-1.14.0\nginx.exe</stopexecutable>
- <stopargument>-p</stopargument>
- <stopargument>D:\softs\nginx-1.14.0</stopargument>
- <stopargument>-s</stopargument>
- <stopargument>stop</stopargument>
- <stoptimeout>6sec</stoptimeout>
- </service>
4. 执行 nginxd.exe install 注册服务
winsw 相关命令:
install to install the service to Windows Service Controller. This command requires some preliminary steps described in the Installation Guide.
uninstall to uninstall the service. The opposite operation of above.
start to start the service. The service must have already been installed.
stop to stop the service.
restart to restart the service. If the service is not currently running, this command acts like start.
status to check the current status of the service.
This command prints one line to the console.
NonExistent indicates the service is not currently installed
Started to indicate the service is currently running
Stopped to indicate that the service is installed but not currently running.
5. 通过 windows 系统 NET 命令启动
net start nginx 启动
net stop nginx 停止
net 相关命令:
- NET
- [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
- HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
- STATISTICS | STOP | TIME | USE | USER | VIEW ]
以上.
来源: http://www.jianshu.com/p/e2dd8c4b5ba5