到官网下载来nginx的解压包,解压之后 双击nginx.exe 一闪而过,此时nginx已经在进程里面了。第二种启动方式 :cmd到nginx.exe所在目录 , 输入 > nginx 回车, 此时会处于繁忙状态 , 第三种启动方式 : >start nginx 回车。
注:nginx 默认端口为80 ,请确认没有冲突。
主配置文件:conf/nginx.conf 。如果更改了配置文件 需要重启nginx 或者执行 >nginx -s reload . 重新加载配置文件 。
停止:强制停止>nginx -s stop 优雅停止>nginx -s quit
重新打开日志文件 >nginx -s reopen
打开了nginx , 在浏览器输入; localhost 会跳到nginx页面
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html/data/www;
#index index.html index.htm;
proxy_pass http://localhost:8080/;
}
location /images/ {
root html/data;
} }
上面这段为nginx.conf 中的一部分配置,
server 代表一个服务端 ,
listen 监听的端口 ,
server_name 主机名 ,
location / 代表配置URL 然后处理的规则
root 作为根目录
index 为默认页面
比如 location /{
root html/data/www;
index index.html;
}
表示输入 localhost时 nginx会到 html/data/www目录 下找index.html 页面,如没有则404
输入 localhost/haha.html 会到 html/data/www目录下找 haha.html 页面
比如 localhost /images/{
root html/data; #注意 末位要有分号 否则报错
}
输入localhost/images/haha.png 时 会到 html/data/images 目录下找 haha.png 。
proxy_pass 代表 代理的URL
比如 输入 localhost/login.jsp 会到 http://localhost:8080/login.jsp 页面
如果我的项目为 /slzh 则需要将它的上下文路径配置为 / 不然会有不一致的资源url。