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

在默认的文件中添加上:

1 #静态文件 2 server { 3 listen 80; 4 server_name static.cnblog.com; 5 6 location / { 7 root D:/source/static_cnblog_com; 8 } 9 } 10这个是自己定义的文件地址 11
1#user nobody; 2worker_processes 1; 3 4#error_log logs/error.log; 5#error_log logs/error.log notice; 6#error_log logs/error.log info; 7 8#pid logs/nginx.pid; 9 10 11events { 12 worker_connections 1024; 13} 14 15 16http { 17 include mime.types; 18 default_type application/octet-stream; 19 20 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 # '$status $body_bytes_sent "$http_referer" ' 22 # '"$http_user_agent" "$http_x_forwarded_for"'; 23 24 #access_log logs/access.log main; 25 26 sendfile on; 27 #tcp_nopush on; 28 29 #keepalive_timeout 0; 30 keepalive_timeout 65; 31 32 #gzip on; 33 34 #静态文件 35 server { 36 listen 80; 37 server_name static.cnblog.com; 38 39 location / { 40 root D:/source/static_cnblog_com; 41 } 42 } 43 44 server { 45 46 47 # 1.侦听80端口 48 listen 80; 49 server_name localhost; 50 51 location / { 52 # 2. 默认主页目录在nginx安装目录的html子目录。 53 root html; 54 index index.html index.htm; 55 } 56 error_page 500 502 503 504 /50x.html; 57 location = /50x.html { 58 root html; 59 } 60 61 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 62 # 63 #location ~ \.php$ { 64 # proxy_pass http://127.0.0.1; 65 #} 66 67 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 68 # 69 #location ~ \.php$ { 70 # root html; 71 # fastcgi_pass 127.0.0.1:9000; 72 # fastcgi_index index.php; 73 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 74 # include fastcgi_params; 75 #} 76 77 # deny access to .htaccess files, if Apache's document root 78 # concurs with nginx's one 79 # 80 #location ~ /\.ht { 81 # deny all; 82 #} 83 } 84 85 86 # another virtual host using mix of IP-, name-, and port-based configuration 87 # 88 #server { 89 # listen 8000; 90 # listen somename:8080; 91 # server_name somename alias another.alias; 92 93 # location / { 94 # root html; 95 # index index.html index.htm; 96 # } 97 #} 98 99 100 # HTTPS server 101 # 102 #server { 103 # listen 443 ssl; 104 # server_name localhost; 105 106 # ssl_certificate cert.pem; 107 # ssl_certificate_key cert.key; 108 109 # ssl_session_cache shared:SSL:1m; 110 # ssl_session_timeout 5m; 111 112 # ssl_ciphers HIGH:!aNULL:!MD5; 113 # ssl_prefer_server_ciphers on; 114 115 # location / { 116 # root html; 117 # index index.html index.htm; 118 # } 119 #} 120 121} 122

 

 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

 

转载于:https://www.cnblogs.com/wyf-love-dch/p/7428069.html

代码交流 2021