nginx在windows系统的安装和部署

nginx功能之一:启动一个本地服务器,通过配置server_name和root目录等来访问目标文件

1. 下载的地址:http://nginx.org/en/download.html

注意下载的时候尽量下载比较稳定的版本,我用的是nginx-1.8.1版本

 

可以直接输入地址: http://nginx.org/download/nginx-1.8.1.zip  下载。

 

2下载完,将压缩包解压到D盘即可。

     

解压完的压缩文件中不包含上图中的img文件夹,这是我自建的存放图片的文件夹

 

3.nginx配置文件在 nginx-1.8.0\conf\nginx.conf

在默认的文件中添加上:

    #静态文件
    server {
        listen       80;
        server_name  static.cnblog.com;

        location / {
            root   D:/source/static_cnblog_com;
        }
    }
这个是自己定义的文件地址
#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  static.cnblog.com;

        location / {
            root   D:/source/static_cnblog_com;
        }
    }

    server {


        # 1.侦听80端口
        listen       80;
        server_name  localhost;

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

}

 

 4.点击nginx.exe运行,在浏览器中输入127.0.0.1  或者 localhost    

  可以看到如下所示的默认页面,证明你的本地的nginx部署成功。

下面简单介绍一下几个常见的命令:(注意必须进入到nginx的安装目录下才能使用)

在nginx.exe目录,打开命令行工具,用命令 启动/关闭/重启nginx

start nginx : 启动nginx
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:
nginx -s stop :快速停止nginx
nginx -s quit :完整有序的停止nginx

 

posted @ 2017-08-25 14:58  坠落凡尘的魔鬼  阅读(713)  评论(0编辑  收藏  举报