Windows下安装以及配置nginx

第一步

下载nginx地址为:http://nginx.org/en/download.html。建议下载稳定版本。如下图所示:

 

第二步

将下载的压缩文件解压到本地如我解压到了:D:\nginx-1.8.1,进入nginx目录 双击nginx.exe 来启动nginx

第三步

测试,此时 直接在浏览器地址栏输入:localhost 便能看到 欢迎页面,说明你虚拟主机已经搭建好了

 

相关配置

在nginx的安装目录的conf目录下有一个nginx.conf。如下:

 

<span style="font-size:14px;">#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 {
        #1.侦听80端口
       listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        # 2. 默认主页目录在nginx安装目录的html子目录。
           root   html;
            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;
    #    }
    #}

}
</span>

 

上述关于配置文件做了简单描述,更高级的应用有待研究。

相关命令

查看nginx进程

tasklist /fi "imagename eq nginx.exe" 显示如下图:

nginx常用命令(一定要进入nginx的安装目录才能执行)

 

nginx -s stop 强制关闭
nginx -s quit 安全关闭
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效
nginx -s reopen 打开日志文件

 

 

 

 

 

 

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
为了在Windows安装配置Nginx,你可以参考以下步骤: 1. 首先,你需要下载NginxWindows版本安装程序,可以在官方网站或第三方网站上找到适合你的版本。然后双击运行安装程序开始安装。 2. 安装程序会要求你选择安装位置和一些其他配置选项。你可以按照默认设置进行安装,或者根据需要进行自定义配置。 3. 安装完成后,你可以在指定的安装位置找到Nginx安装目录。在这个目录中,你会找到一个名为"nginx.exe"的可执行文件。 4. 在安装目录中找到一个名为"nginx.conf"的配置文件。你可以使用文本编辑器打开这个文件,根据你的需求进行配置更改。 5. 配置文件中包含了Nginx的各种设置和规则,你可以根据需要进行修改。例如,你可以设置Nginx监听的端口、管理访问路径的规则等。 6. 如果你修改了配置文件,需要重启Nginx才能使更改生效。你可以使用命令行工具打开安装目录,进入到Nginx安装目录,然后使用命令"nginx -s reload"来重新加载配置文件。 7. 你还可以使用其他命令来启动、停止、重启Nginx,具体命令可以参考中提供的相关启动命令。 请注意,如果在使用命令时遇到报错,可能是因为命令不在系统的环境变量中。你可以尝试在命令前加上"./"或者使用Windows自带的命令行工具运行。 通过按照以上步骤,你就能在Windows上成功安装配置Nginx了。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JAIR_FOREVER

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值