nginx的一些知识

1.随便启动一个nginx实例,只是为了复制出配置

        docker run -p80:80 --name nginx -d nginx:1.10   

2.将容器内的配置文件拷贝到/mydata/nginx/conf/ 下

 3.终止原容器

        docker stop nginx
4.执行命令删除原容器:

        docker rm nginx

5.创建新的Nginx,执行以下命令

   

 6.设置开机启动nginx

        docker update nginx --restart=always
7.创建“/mydata/nginx/html/index.html”文件,测试是否能够正常访问

        echo '<h2>hello nginx!</h2>' >index.html
        访问:http://nginx所在主机的IP:80/index.html

8.nginx配置文件

(2)nginx.config

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    upstream venusmall{
        # 88是网关
        server 192.168.56.1:88;
    }

    include /etc/nginx/conf.d/*.conf;  # 包含了哪些配置文件
}
server {
    listen       80;
    #匹配的host,如果都没有匹配,默认走第一个server模块
    server_name gulimall.com  *.gulimall.com; 
   

    location /static {
        root   /usr/share/nginx/html;
    }

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    
    #会找到upstream的venusmall的设定
    location / {
        proxy_pass http://venusmall;
        proxy_set_header Host $host;  #nginx反向代理时,需要把host重新设置
    }
  

    include /etc/nginx/conf.d/*.conf;  # 包含了哪些配置文件
}

 9.官网

nginx documentationhttps://nginx.org/en/docs/10.设置反向代理

       修改hosts文件或者购买域名,将域名与 nginx所在的服务器ip相对应上

        添加nginx的server模块,设置监听端口,server_name, location,配置网关负载均衡,见上图。

11.动静分离配置

#http://venusmall.com/static/index/img/zhongchou.png 
#/usr/share/nginx/html/static/index/img/zhongchou.png 就是最终的路径
location /static/ {
   root  /usr/share/nginx/html;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值