一、前端学习本地项目部署
二 下载安装包
官网下载: 下载地址:nginx.org/en/download…
网页上有三个版本:简单介绍一下:
-
Mainline version : 主线版本 ,最新的主线版本是 nginx/Windows-1.23.3
-
Stable version : 稳定版本【工作中要更新最新版本就可以使用稳定版本】
-
Legacy versions :历史版本
三 解压和解压包
我现在的是nginx/Windows-1.23.3 ,下载完成对应的压缩包为: nginx-1.23.3.zip,进行解压操作!
【注:解压的目录一定不要含有中文,否则访问出错!】
解压后的目录如下,不一一介绍了,简单介绍如下图:
四 验证安装 [默认配置]
注意不要直接双击nginx.exe,这样会导致修改配置后重启、停止nginx无效,需要手动关闭任务管理器内的所有nginx进程。
执行启动命令 ,有一个一闪而过的效果!
start nginx
访问 http://localhost:80,启动成功如图:
如果启动成功,但是访问不了,请查询log/error.log 文件!
常见的错误:
(1)端口号被占用
(2)nginx文件夹路径含中文(1113: No mapping for the Unicode character exists in the target multi-byte code page)
五、Nginx.conf配置
1、下面是进行nginx.conf配置,命令如下
cd conf
vim nginx.conf
2、修改文件中的内容如下所示
#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 8888;
server_name 192.168.8.145;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist/;
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;
#}
}
}
六、总结
本文主要讲述了Nginx在windows系统下的搭建过程。
重新启动
nginx -s reload
关闭nginx服务
nginx -s stop
退出服务
nginx -s quit
先使用以下命令查看当前进程
netstat -ntlp
kill命令杀掉进程
kill 2054