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

Windows下 Nginx安装与配置

一、下载

过程省略

二、配置

首先进入nginx安装目录(nginx.exe同级),编辑conf/nginx.conf文件


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8800;
        server_name  localhost;

        #charset koi8-r;
         charset utf-8;


        #access_log  logs/host.access.log  main;

        location / {
            root   html; #表示项目文件所处于的位置,在windows下面表示的是与conf目录处于同一级
            index  index.html index.htm;
        }

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

三、常规启动:

  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:\nginx-1.16.0\nginx.exe</executable>
  <startargument>-p</startargument>
  <startargument>D:\nginx-1.16.0</startargument>  
  <logpath>D:\nginx-1.16.0/logs</logpath>
  <logmode>roll</logmode>  
  <stopexecutable>D:\nginx-1.16.0\nginx.exe</stopexecutable>
  <stopargument>-p</stopargument>
  <stopargument>D:\nginx-1.16.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相关命令:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值