Nginx安装
创始人
2024-04-21 16:41:59
0

🍁博客主页:👉不会压弯的小飞侠
✨欢迎关注:👉点赞👍收藏⭐留言✒
✨系列专栏:👉Linux专栏
🔥欢迎大佬指正,一起学习!一起加油!

在这里插入图片描述

目录

  • 🍁简介
  • 🍁正向代理
  • 🍁反向代理
  • 🍁负载均衡
  • 🍁动静分离
  • 🍁Nginx在线安装
  • 🍁nginx常用的命令
  • 🍁nginx.conf 配置文件
  • 🍁访问Nginx首页


🍁简介

  • Nginx 是一个高性能的HTTP和反向代理服务器
  • 特点:
    • 占有内存少
    • 并发能力强

🍁正向代理

  • Nginx不仅可以做反向代理,实现负载均衡,还能用作正向代理来进行上网等功能。
  • 正向代理服务器时位于客户端和服务器之间,客户端为了从服务器获取数据,必须向代理服务器发送一个请求。并指定目标服务器,代理服务器将目标服务器返回的数据转交给客户端。

🍁反向代理

  • 反向代理:其实客户端对代理是无感知的,因为客户端不需要任何配置就可以访问,只需要将请求发送到反向代理服务器,由反向代理服务器去选择目标服务器获取数据后,在返回给客户端,此时反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器IP地址。

🍁负载均衡

  • 在访问量较多的时候,可以通过负载均衡,将多个请求分摊到多台服务器上,相当于把一台服务器需要承担的负载量交给多台服务器处理,进而提高系统的吞吐率;另外如果其中某一台服务器挂掉,其他服务器还可以正常提供服务,以此来提高系统的可伸缩性与可靠性。

🍁动静分离

  • 为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。降低原来单个服务器的压力。

🍁Nginx在线安装

  • 需要的安装包:

    • pcre-8.37.tar.gz
    • openssl-1.0.1t.tar.gz
    • zlib-1.2.8.tar.gz
    • nginx-1.12.2.tar.gz
  • 在finalshell中上传安装包:
    在这里插入图片描述

    • 安装pcre

      • 第一步 联网下载pcre-8.37.tar.gz
      • 第二步 解压压缩文件
        • 命令 tar -zxvf pcre-8.37.tar.gz
      • 第三步 ./configure完成后,回到pcre目录下执行make,最后执行make install
      • 第四步 pcre-config --version 检查版本
    • 安装openssl 、zlib 、 gcc 依赖

      • yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
    • 安装nginx

      • 使用命令解压:
      • ./configure
      • make && make install
      • 进入目录 /usr/local/nginx/sbin 执行./nginx 启动服务
    • 启动查进程:

[root@192 sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@192 sbin]# ps -ef | grep nginx
root      53563      1  0 23:51 ?        00:00:00 nginx: master process ./nginx
nobody    53564  53563  0 23:51 ?        00:00:00 nginx: worker process
root      55529   1582  0 23:53 pts/0    00:00:00 grep --color=auto nginx
[root@192 sbin]# 
  • 关进程:
 ./nginx -s stop

🍁nginx常用的命令

  • 启动命令
    在/usr/local/nginx/sbin目录下执行 ./nginx
  • 关闭命令
    在/usr/local/nginx/sbin目录下执行 ./nginx -s stop
  • 重新加载命令
    在/usr/local/nginx/sbin目录下执行 ./nginx -s reload
  • 查看版本
    ./nginx -v
  • 查看进程
    ps -ef | grep nginx

🍁nginx.conf 配置文件

  • nginx 安装目录(/usr/local/nginx/conf/nginx.conf)下,其默认的配置文件都放在这个目录的 conf 目录下,而主配置文件 nginx.conf 也在其中,配置文件进行相应的修改:
  • vim nginx.conf
#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       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  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   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   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;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}

1.全局块

  • worker_processes 值越大,可以支持的并发处理量也越多

2.events块

  • 每个 work process 可以同时支持的最大连接数等,上面 work process 支持的最大连接数为 1024.

3.http块

  • http 块也可以包括 http全局块、server 块。
  • 代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这配置。

🍁访问Nginx首页

  • 关闭防火墙,访问nginx
    • 在windows系统中访问linux中nginx,默认不能访问的,因为防火墙问题
    • 关闭防火墙-开放访问的端口号,80端口
    • 查看开放的端口号
    • firewall-cmd --list-all
    • 设置开放的服务或端口号
    • firewall-cmd --add-service=http --permanent
    • firewall-cmd --add-port=80/tcp --permanent
    • 重启防火墙
    • firewall-cmd --reload
  • 重新启动Nginx
    • ./nginx
  • 去浏览器输入ip地址80可以省略(不成功,端口号占用问题)
    • 解决方法有两种,一种是换端口,另一种是查看占用端口的进程,把它关掉。
[root@192 sbin]# netstat -ntlp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      89740/nginx: worker 
[root@192 sbin]# kill -9 89740
  • 重启nginx服务,浏览器输入ip地址:

在这里插入图片描述

相关内容

热门资讯

电视安卓系统哪个品牌好,哪家品... 你有没有想过,家里的电视是不是该升级换代了呢?现在市面上电视品牌琳琅满目,各种操作系统也是让人眼花缭...
安卓会员管理系统怎么用,提升服... 你有没有想过,手机里那些你爱不释手的APP,背后其实有个强大的会员管理系统在默默支持呢?没错,就是那...
安卓系统软件使用技巧,解锁软件... 你有没有发现,用安卓手机的时候,总有一些小技巧能让你玩得更溜?别小看了这些小细节,它们可是能让你的手...
安卓系统提示音替换 你知道吗?手机里那个时不时响起的提示音,有时候真的能让人心情大好,有时候又让人抓狂不已。今天,就让我...
安卓开机不了系统更新 手机突然开不了机,系统更新还卡在那里,这可真是让人头疼的问题啊!你是不是也遇到了这种情况?别急,今天...
安卓系统中微信视频,安卓系统下... 你有没有发现,现在用手机聊天,视频通话简直成了标配!尤其是咱们安卓系统的小伙伴们,微信视频功能更是用...
安卓系统是服务器,服务器端的智... 你知道吗?在科技的世界里,安卓系统可是个超级明星呢!它不仅仅是个手机操作系统,竟然还能成为服务器的得...
pc电脑安卓系统下载软件,轻松... 你有没有想过,你的PC电脑上安装了安卓系统,是不是瞬间觉得世界都大不一样了呢?没错,就是那种“一机在...
电影院购票系统安卓,便捷观影新... 你有没有想过,在繁忙的生活中,一部好电影就像是一剂强心针,能瞬间让你放松心情?而我今天要和你分享的,...
安卓系统可以写程序? 你有没有想过,安卓系统竟然也能写程序呢?没错,你没听错!这个我们日常使用的智能手机操作系统,竟然有着...
安卓系统架构书籍推荐,权威书籍... 你有没有想过,想要深入了解安卓系统架构,却不知道从何下手?别急,今天我就要给你推荐几本超级实用的书籍...
安卓系统看到的炸弹,技术解析与... 安卓系统看到的炸弹——揭秘手机中的隐形威胁在数字化时代,智能手机已经成为我们生活中不可或缺的一部分。...
鸿蒙系统有安卓文件,畅享多平台... 你知道吗?最近在科技圈里,有个大新闻可是闹得沸沸扬扬的,那就是鸿蒙系统竟然有了安卓文件!是不是觉得有...
宝马安卓车机系统切换,驾驭未来... 你有没有发现,现在的汽车越来越智能了?尤其是那些豪华品牌,比如宝马,它们的内饰里那个大屏幕,简直就像...
p30退回安卓系统 你有没有听说最近P30的用户们都在忙活一件大事?没错,就是他们的手机要退回安卓系统啦!这可不是一个简...
oppoa57安卓原生系统,原... 你有没有发现,最近OPPO A57这款手机在安卓原生系统上的表现真是让人眼前一亮呢?今天,就让我带你...
安卓系统输入法联想,安卓系统输... 你有没有发现,手机上的输入法真的是个神奇的小助手呢?尤其是安卓系统的输入法,简直就是智能生活的点睛之...
怎么进入安卓刷机系统,安卓刷机... 亲爱的手机控们,你是否曾对安卓手机的刷机系统充满好奇?想要解锁手机潜能,体验全新的系统魅力?别急,今...
安卓系统程序有病毒 你知道吗?在这个数字化时代,手机已经成了我们生活中不可或缺的好伙伴。但是,你知道吗?即使是安卓系统,...
奥迪中控安卓系统下载,畅享智能... 你有没有发现,现在汽车的中控系统越来越智能了?尤其是奥迪这种豪华品牌,他们的中控系统简直就是科技与艺...