• 微信
当前位置:首页 >> 建站学院 >> 网站建设

如何在Windows环境配置 Nginx?

作者:玄北 时间:2022-07-26 阅读数:164人阅读

部署

1、首先,从官网下载 Nginx 包,版本自己选择,官网地址:传送门

如何在Windows环境配置 Nginx?


2、然后,选择 Windows 版本的安装包进行下载(大家根据自己实际情况下载对应版本),根据图片描述,最新版是 1.23.1 (具体看当前官网),稳定版是 1.22.0 (具体看当前官网):

如何在Windows环境配置 Nginx?

3、我们选择合适的版本下载到本地后,用解压程序进行解压,得到一个文件夹,将文件夹复制到指定目录就完成了安装,解压后得到的 .exe 文件不要双击!

注意:一定不要直接双击nginx.exe,这样会导致修改配置后重启、停止 nginx 无效,需要手动关闭任务管理器内的所有 nginx 进程,再启动才可以。

4、启动 Nginx

# 进入 Nginx 所在目录
cd D:
ginx-1.xx.x

# 启动 Nginx 服务
start nginx  # 执行后会有一闪而过的信息,是正常的

# 查看任务进程是否存在,可使用以下命令s或打开任务管理器都行
tasklist /fi "imagename eq nginx.exe"

# 日志路径 c:
ginx-1.xx.xlog

5、到浏览器访问 127.0.0.1:80,查看是否成功,看到以下页面表示成功:

如何在Windows环境配置 Nginx?


文档结构

如何在Windows环境配置 Nginx?

默认配置文件路径 D:/nginx-1.xx.x/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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            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;
    #    }
    #}

}

注意事项

  1. Nginx 默认端口号为 80,若已被占用则无法启动,可在配置文件中修改端口号,修改配置后可执行命令检查配置是否合法。

  2. Nginx 文件夹路径不要包含中文。

over~~~

       

转载请注明——本文源自【玄北博客】www.xuanbeiweb.cn

免责声明:本站部分文章、数据、图片来自互联网,

如果侵犯了你的权益请来信告知我们删除,否则不承担相应法律责任。邮箱:xuanbei@xuanbeiweb.cn

标签:
玄北头像

玄北

Hi~如果您正好看到这里,可以扫一扫微信二维码加我为好友,我是一个喜欢交朋友的人,我知道您也是哦~

玄北微信

发表评论:

评论记录:

暂无评论——欢迎您的点评!