- nginx (windows启动)
启动nginx:start nginx nginx
中止nginx: nginx -s stop nginx -s quit
从新载入 nginx:nginx -s reload
从新打开日志文件:nginx -s reopen
查看nginx -v:运行nginx -V能够查看该Win32平台编译版支持哪些模块
nginx: [error] open() " E:\nginx\nginx\nginx-1.10.2\logs\nginx.pid" failed (2: No such file or directory)
解决方式:启动nginx 改成指定配置文件路径:nginx -c E:\nginx\nginx\nginx-1.10.2\conf\nginx.conf
- nginx(反向代理配置)
http {
...
#设定负载均衡的服务器列表
#weigth参数表示权值,权值越高被分配到的概率越大(可配置多台服务器,自动分配代理到哪台服务器)
upstream 192.168.0.22{
server 192.168.0.27:8080 weight=1;
...
}
#upstream server{
# server 192.168.0.27:8080 weight=1;
#}
server {
listen 80; #端口号
server_name localhost;
location / {
proxy_pass http://192.168.0.22;
#proxy_pass http://server;
#root html;
#index index.html index.htm;
}
...
}
...
}
若是反向代理的页面有静态资源连接,IP会被替换为服务列表名
例:原静态资源地址: http://192.168.0.27:8080/Esell/css/style.css 会替换为:
http://192.168.0.22:22:80/Esell/css/style.css
使用第二个屏蔽配置:http://192.168.0.27:8080/Esell/css/style.css 会替换为:
http://server:80/Esell/css/style.css
- 配置说明
默认静态页面路径在安装程序下html,若是要从新配置录入全路径
- Nignx注册Windows服务
下载 windows service wrapper;
拷贝winsw-1.8-bin.exe 到nginx主目录,修改程序名为myapp.exe,建立配置文件myapp.xml:
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>D:\nginx-1.10.2\nginx.exe</executable>
<logpath>D:\nginx-1.10.2\logs</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p D:\nginx-1.10.2</startargument>
<stopargument>-p D:\nginx-1.10.2 -s stop</stopargument>
</service>
安装服务:cd /d D:\nginx-1.10.2\; myapp.exe install,服务被注册到Windows服务