2016-12-15 Nginx 之初学者(一)

到官网下载来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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值