Nginx

1|0宿主机安装


建议安装在宿主机,反向代理时,使用127.0.0.1映射docker应用容器的端口

(docker安装的话,外网->nginx 容器 ->宿主机->  应用的容器,会有更多的网络损耗)

复制代码
#宿主机上安装 nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y

#版本:nginx -v
#目录:/etc/nginx
#配置:/etc/nginx/conf.d/default.conf

#启动
sudo systemctl start nginx.service
#开机自动启动
sudo systemctl enable nginx.service 
复制代码

2|0 Docker 安装 


1
2
# -d 后台运行   -p 端口映射   -v 挂在数据卷   --restart=always 自动启动
docker run --name nginx -d -p 80:80 --restart=always -v /data/nginx/conf.d:/etc/nginx/conf.d -v /data/nginx/html:/usr/share/nginx/html nginx:latest

  

3|0配置 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cd /data/nginx/conf.d
vim default.confserver {
    listen       80;
    server_name  localhost;
 
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
 
    location / {
        root   /usr/share/nginx/html;
        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   /usr/share/nginx/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;
    #}
}

  

默认首页

1
2
3
cd /data/nginx/html
 
vim index.html

  

1
2
3
#配置成功后,可以将容器commit为一个新的image
#-a :提交的镜像作者;  -c :使用Dockerfile指令来创建镜像;-m :提交时的说明文字; -p :在commit时,将容器暂停。
docker commit -a "fmp" -m "mynginx" a404c6c174a2 mynginx:v1

  

  nginx配置参考:https://www.cnblogs.com/lich1x/p/11225528.html


__EOF__

作  者码农搞事情
出  处https://www.cnblogs.com/fmp/p/11486159.html
关于博主:一本正经写程序&不务正业搞事情
版权声明:欢迎分享,转载请注明出处。
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!

posted @   码农搞事情  阅读(214)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
0
0
关注
跳至底部
点击右上角即可分享
微信分享提示