nginx初级入门学习指南—学习笔记

nginx常用命令

  • 开启服务:start nginx
  • 停止服务:nginx -s stop;nginx -s quit
    注:nginx停止命令stop与quit参数的区别在于stop是快速停止nginx,可能并不保存相关信息,quit是完整有序的停止nginx ,并保存相关信息。
  • 重启服务:nginx -s reload;也就是nginx热部署,不需要关闭和启动服务;

ngnix配置文件


#user  nobody;
# 工作进程数量,一般设置为本机的cpu数量
worker_processes  8;
#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    # include用来对外部文件配置的引用
    include       mime.types;#引入外部mine.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;#指定 KeepAlive 的超时时间(timeout),指定每个 TCP 连接最多可以保持多长时间

    #gzip  on;

    server {
        listen       8686;#服务监听端口
        server_name  localhost;#服务名称

        #charset koi8-r;

        #路由/重定向的文件地址
		location / {
		    root    html; #文件夹地址
			index  index.html index.htm;#默认文件名称
		}
		
		#配置一个项目发布
		location /project {
		    alias    data/dist; #路由转换到/project时,服务重定向访问文件的位置
			index  index.html index.htm;
		}
		
	    location /data3d {
		    alias    data/geobody_3dtiles;
			index  tileset.json;
			add_header Access-Control-Allow-Origin *;#跨域设置
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,Authorization,Accept,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
		}

        #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;#反向代理
        }
    }
}

root和alias区别

相同点:root 和 alias 都可以定义在 location 模块中,都是用来指定请求资源的真实路径。
不同点:
root:root 则是最上层目录的定义,
如:location /project {
root: dist
}
那么在服务器里面对应的真正的资源路径为:dist/project,即资源路径为root+location指定值的组合
alias: 是一个目录别名的定义
同如:location /project {
alias: dist
}
那么在服务器里面对应的真正的资源路径为:dist,即资源路径为alias制定的路径地址,与location指定值无关。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ponGISer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值