在windows上安装nginx并注册

一、前言

  最近自己也尝试了一下在windows上安装nginx,其实非常的简单,这里算是备忘一下。

二、在windows下面安装

  首先需要到nginx的官网上下载最新版的nginxhttp://nginx.org/en/download.html

  找到最新版本下载即可:

  至于后面的pgp,其实是一种密钥机制(pretty good privacy)。

  下载之后,我们发现这个文件是不用安装的,也就是不需要在windows的注册表中注册的,因此我们可以直接使用,如果大家有使用过masm之类的汇编软件,相信大家会理解的,之后,我们就可以直接在cmd中运行了,这个时候可能会出现问题,其中一个问题是闪退。

  闪退的原因有很多种,我们要注意查看日志文件:

  如果大家遇到下图中我画出的问题:

 // :: [emerg] #: CreateFile() "C:\Users\爱好妹子的朱\Desktop\nginx-1.13.7/conf/nginx.conf" failed (: No mapping for the Unicode character exists in the target multi-byte code page)

    那么原因其实很简单,我们读了日志之后就能理解,不能映射编码,说明我们肯定是在路径中有中文字符,也就是我们的文件存放目录一定不能是中文的,要不然肯定会闪退的。

  解决办法就是把下载的文件放到全英文的目录之中。

  还有一个错误是:

  绑定端口异常,那肯定呀,80端口是默认让http协议使用的,我们这里肯定不能占用,同时我们也可以回忆一下常用的端口,比如HTTPS(443),ftp(20,21)等等。

  解决办法也很简单,只需要在NGINX中修改一下配置即可:

  我们在sublime中打开该文件:

  就可以看到相应的配置信息,比如IP地址和端口,这里笔者已经改成了一个大于1024的端口了(其他任意)。

  让我们仔细看一下配置文件,我们以后的很多操作都可以从中配置:

   #user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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 ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 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;
# }
#} }

三、将nignx注册成服务

如果我们经常使用,那么在cmd之中启动是非常不方便的,因此,我们可以将其注册成服务

首先我们下载Windows Service Wrapper(比如winsw-1.8-bin.exe服务注册工具,然后将这个工具放到ngnix安装目录之下,然后新建一个文件,这个文件的文件名需要和我们的服务注册工具一致,也就是说如果把服务注册工具重命名,那么这个文件也需要重命名(winsw-1.8-bin.xml):

 <?xml version="1.0" encoding="UTF-8" ?>
<service>
<id>nginx</id>
<name>zyrNginx Service</name>
<description>High Performance Nginx Service 朱彦荣 zyr</description>
<executable>D:\nginx-1.14.\nginx.exe</executable>
<logpath>D:\nginx-1.14.\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p D:\nginx-1.14.</startargument>
<stopargument>-p D:\nginx-1.14. -s stop</stopargument>
</service>

    注意上面的文件我们要修改nginx存放的目录,以及相关的配置。

    然后我们在命令行(管理员模式,不然权限不够)中,将该服务注册到windows系统之中:

    最后我们打开任务管理器中的服务,可以发现我们自己命名的服务已经出现了:

在windows上安装nginx的更多相关文章

  1. 在windows上安装nginx并注册

    在windows上安装nginx并注册 一.前言   最近自己也尝试了一下在windows上安装nginx,其实非常的简单,这里算是备忘一下. 二.在windows下面安装   首先需要到nginx的 ...

  2. 在Linux和Windows系统上安装Nginx服务器的教程

    在Linux和Windows系统上安装Nginx服务器的教程  1.在CentOS系统上安装Nginx 在 CentOS6 版本的 EPEL 源中,已经加入了 nginx 的 rpm 包,不过此 RP ...

  3. Windows 编译安装 nginx 服务器 + rtmp 模块

    有关博客: <Windows 编译安装 nginx 服务器 + rtmp 模块>.<Ubuntu 编译安装 nginx>.<Arm-Linux 移植 Nginx> ...

  4. WordPress安装篇(2):用宝塔面板在Windows上安装WordPress

    上一篇文章介绍了如何使用PHPStudy工具在Windows Server环境安装WordPress,接下来介绍一款更加强大的部署WordPress的集成工具--宝塔面板.宝塔面板不仅提供免费版本,还 ...

  5. 在Windows上安装Elasticsearch 5.0

    在windows上安装Elasticsearch Elasticsearch可以使用.zip软件包安装在Windows上. elasticsearch-service.bat命令,它将设置Elasti ...

  6. 在 Windows 上安装Rabbit MQ 指南

    rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议.采用 Erlang 实现的工业级的消息队列(MQ)服务器. Ra ...

  7. windows下安装nginx

    说起开发,自己感到非常惭愧,由于公司让我给<绿电侠>项目写整体架构解决方案,才开始接触nginx这个东东,突然觉得它是一把非常好的利器. 本文主要记录在windows下安装nginx,另参 ...

  8. 在Windows上安装虚拟机详细图文教程

    用虚拟机来安装最新的软件,安装最新的系统等等比较保险,可以避免安装不顺利影响自己原来的系统和应用,想尝鲜又担心自己完全更换系统不适应的朋友可以尝试. 虚拟机下载:https://yunpan.cn/c ...

  9. 在windows上安装ASP.NET 5(译文)

    本文将介绍如何在windows上安装ASP.NET5,包括单独安装和通过Visual Studio 2015 安装. 本文包括: 通过Visual Studio安装ASP.NET 单独安装ASP.NE ...

随机推荐

  1. ScrollView(RecyclerView等)为什么会自动滚动原理分析,还有阻止自动滑动的解决方案

    引言,有一天我在调试一个界面,xml布局里面包含Scroll View,里面嵌套了recyclerView的时候,界面一进去,就自动滚动到了recyclerView的那部分,百思不得其解,上网查了好多 ...

  2. pandas读取excel中指定数据的行数

    shuju = pd.read_excel(filename) loandata = pd.DataFrame(shuju) ncol = (len(loandata.keys())) data = ...

  3. kafka学习

    kafka名词解释和工作方式: Producer :消息生产者,就是向kafka broker发消息的客户端. Consumer :消息消费者,向kafka broker取消息的客户端 Topic : ...

  4. 自己模拟的一个简单的web服务器

    首先我为大家推荐一本书:How Tomcat Works.这本书讲的很详细的,虽然实际开发中我们并不会自己去写一个tomcat,但是对于了解Tomcat是如何工作的还是很有必要的. Servlet容器 ...

  5. XML,HTML,XHTML

    对于上面3种技术,我们经常使用到,这里具体的做一个总结,来对比一下这3个东西. 什么是XML? XML即Extentsible Markup Language(可扩展标记语言),是用来定义其它语言的一 ...

  6. maven-assembly-plugin插件的使用方法

    一. Assembly 是什么意思? 二. maven-assembly-plugin是什么? 它是maven中针对打包任务而提供的标准插件. 三. maven-assembly-plugin插件的作 ...

  7. 【转】matlab图形句柄详解(一)

    在matlab中,每一个对象都有一个数字来标识,叫做句柄.当每次创建一个对象时,matlab就为它建立一个唯一的句柄,句柄中包含有该对象的相关信息参数,可以在后续程序中进行操作,改变其中的参数,以便达 ...

  8. 【转】Shell执行MySql操作

    mysql  -hhostname -Pport -uusername -ppassword  -e  相关mysql的sql语句,不用在mysql的提示符下运行mysql,即可以在shell中操作m ...

  9. ssh密钥分发与ansible

    笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 当我们公司的服务器达到几十台或几百台或更高的时候,利用批量管理工具管理系统是我们要做的 常用的批量管理工具有ans ...

  10. oracle plsql exception例外

    以下plsql程序用的scott用户的dept,emp表. not_data_found例外: --系统列外 set serveroutput on declare pename emp.ename% ...