沙滩星空的博客沙滩星空的博客

Nginx安装和使用

yun安装:

yum install nginx

启动:

systemctl start nginx.service

开机启动

systemctl enable nginx.service

查看编译参数:
nginx -V 输出是标准错误输出,如需重定向文件,则需要 nginx -V 2>>ngx.version.log

nginx -V
nginx version: nginx/1.9.4
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
configure arguments: --prefix=/usr/local/nginx --with-http_realip_module

查看编译时是否支持http_geoip_module模块:

nginx -V 2>&1 | grep "http_geoip_module"

在使用docker过程中,有映射8081端口到PHP应用目录的要求。
流程:公网接受IP:8081请求,8081端口转发到Nginx容器80端口,并反向代理到PHP服务容器。
注: 必须创建后缀为.conf的虚拟主机文件,并挂载目录到NGINX容器/etc/ningx/conf.d路径。虚拟主机文件,必须监听容器内80端口[或容器内其他被宿主机映射的端口]。
NGINX容器没有默认的80端口映射站点。
误把*.conf中的80写成8081。导致宿主机的8081端口进不来。
docker-compose.yml

    ......
    ports:
     - "8081:80"
    volumes:
     - "/mnt/vhost:/etc/nginx/conf.d"
    ......

/etc/nginx/conf.d/vhost.conf

server {
    listen 80;
    server_name localhost;
    root "/mnt/www/site_com/public_html";
    ......
       }

proxy_pass和fastcgi_pass
proxy_pass_fastcgi_pass.png

proxy_pass反向代理实现负载均衡:

upstream backend  {
  server backend1.example.com weight=5;
  server backend2.example.com:8080;
  server unix:/tmp/backend3;
}
 
server {
  location / {
    proxy_pass  http://backend;
  }
}

用fastcgi做PHP负载均衡

upstream myapp {
    server 192.168.20.1:9000; # PHP-FPM 1
    server 192.168.20.2:9000; # PHP-FPM 2
    ......
}
server {
    listen 80;
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /phpfiles$fastcgi_script_name;
        fastcgi_pass myapp;
    }
}

Nginx之负载均衡 https://www.cnblogs.com/jimisun/p/8254192.html
proxy_pass和fastcgi_pass https://blog.csdn.net/weixin_40911543/article/details/87929162
proxy_pass完全拆解 https://my.oschina.net/foreverich/blog/1512304
nginx学习之详细安装篇(二) https://www.cnblogs.com/t-road/p/6732805.html
CentOS7中使用yum安装Nginx的方法

https://www.cnblogs.com/songxingzhu/p/8568432.html

未经允许不得转载:沙滩星空的博客 » Nginx安装和使用

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址