Windows下 Nginx安装与配置,设置开机自启

作者 : 开心源码 本文共2358个字,预计阅读时间需要6分钟 发布时间: 2022-05-12 共67人阅读

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归入系统服务后,通过系统命令管理

  1. start nginx 启动
  2. nginx -s stop 快速中止nginx
  3. nginx -s quit 完整有序的中止nginx
  4. nginx -s reopen 重新打开日志文件
  5. nginx -s reload 重新加载配置
四、设置开机自启:

推荐用Windows Service Wrapper工具来安装自启动服务:

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 ]

以上。

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » Windows下 Nginx安装与配置,设置开机自启

发表回复