Nginx简单使用

article/2025/8/17 6:09:25

安装龙蜥操作系统

镜像文件在这里下载就行 下载之后新建虚拟机 ISO选择刚才下载文件即可
具体配置可以照我来 也可自定义
在这里插入图片描述

基本工具安装

安装一下最基本的网络工具

yum install net-tools openssh-server wget tar make vim -y

测试一下ssh连接 方便后期操作
[图片]在这里插入图片描述

修改主机名

[root@localhost ~]# hostnamectl set-hostname Anneliese   #Anneliese为你想要改成的主机名
[root@localhost ~]# bash
[root@Anneliese ~]#   

查看系统版本

lsb_release -a

在这里插入图片描述

Nginx依赖安装

1.先安装gcc-c++编译器

yum install gcc-c++ -y
yum install -y openssl openssl-devel

2.再安装pcre包

yum install -y pcre pcre-devel

3.再安装zlib包

yum install -y zlib zlib-devel

在这里插入图片描述

Nginx安装

创建目录

在/usr/local/下创建文件nginx文件

mkdir /usr/local/nginx
cd  /usr/local/nginx

下载资源

在网上下nginx包上传至Linux 点这里选择一个版本下载

wget https://nginx.org/download/nginx-1.23.2.tar.gz

解压

解压并进入nginx目录

tar -zxvf nginx-1.23.2.tar.gz
cd nginx-1.23.2

配置

使用nginx默认配置

./configure

在这里插入图片描述

安装

编译安装

make
make install

查看安装路径

查找安装路径

whereis nginx

运行nginx

进入sbin目录,可以看到有一个可执行文件nginx,直接./nginx执行就OK了。

cd /usr/local/nginx/sbin
./nginx   #重启命令

关闭nginx

./nginx -s quit  或者 ./nginx -s stop 

重载nginx

./nginx -s reload

查看是否启动成功

ps -ef | grep nginx

访问页面

然后在网页上访问自己的IP就可以了默认端口为80(出现如下欢迎界面就成功了!)
在这里插入图片描述

设置开启自启动

vim /etc/rc.local#最底部增加这一行
/usr/local/nginx/sbin/nginx

在这里插入图片描述

防火墙配置

查看http服务是否开启

firewall-cmd --query-service http    #返回yes或者no

在这里插入图片描述

永久开放http服务

firewall-cmd --add-service=http --permanent

在这里插入图片描述

重启防火墙

firewall-cmd --reload

在这里插入图片描述

验证是否生效

这里每个人ip地址不一样注意
在这里插入图片描述

虚拟站点的配置(基于不同端口号)

新建两个页面

填写自己想要的信息
在目录 /usr/local/nginx/html 创建两个html文件
在这里插入图片描述

第一个页面

填写一下内容 当然也是要根据自己想填的信息来写

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Hello, xueyue. Thank you for seeing this.</h1>
</body>
</html>

在这里插入图片描述

第二个页面

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Hello, xueyue. Your student number is 2020101934. I miss you.</h1>
</body>
</html>

在这里插入图片描述

更改配置文件监听地址

vim /usr/local/nginx/conf/nginx.conf   #vim使用不熟练也可以用 ftp进行更改

然后在合适的位置添加下面内容 内容里面的 index需要改成自己网页名称

server {listen       8080;server_name  Student;location / {root   html;index  xueyue.html xueyue.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   xueyue.html;}
}server {listen       9090;server_name  Student_Number;location / {root   html;index  Melanie.html Melanie.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}

下面是我的配置文件 可以参考

#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;#}}
server {listen       9090;server_name  localhost;location / {root   html;index  Melanie.html Melanie.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}server {listen       8080;server_name  localhost;location / {root   html;index  xueyue.html xueyue.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}# 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;#    }#}}

重载nginx

./nginx -s reload

防火墙开放端口号

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --add-port=9090/tcp --permanent

在这里插入图片描述

重启防火墙

firewall-cmd --reload

在这里插入图片描述

查看已开放的端口

firewall-cmd --list-all

在这里插入图片描述

访问页面

http://192.168.90.128:8080/
在这里插入图片描述
http://192.168.90.128:9090/
在这里插入图片描述

黑白名单

过于简单 不多说了
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


http://chatgpt.dhexx.cn/article/YjWkmLVC.shtml

相关文章

nginx使用(基于docker)

一、安装Nginx 1. 搜索 nginx 镜像 docker search nginx 2、拉取nginx镜像 docker pull nginx 3、创建容器&#xff0c;设置端口映射、目录映射 配置 user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_co…

Nginx使用及配置

nginx是什么&#xff1f; nginx是俄罗斯人 Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的一个十分轻量级的HTTP服务器。它是一个高性能的HTTP和反向代理服务器&#xff0c;同时也可以作为IMAP/POP3/SMTP的代理服务器。nginx使用的是BSD许可。 Nginx 以事件驱动的方式…

nginx使用以及配置

nginx主要使用的地方就是用来进行反向代理的http服务器, 主流的Web服务器有: 1、Apache&#xff0c;开源免费&#xff0c;具有简单、高速、性能稳定等特点&#xff0c;可作代理服务器使用; 2、Nginx&#xff0c;是一种高性能的HTTP和反向代理web服务器&#xff0c;支持高并发…

Nginx介绍及基本使用

1.介绍 Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件&#xff08;IMAP/POP3&#xff09;代理服务器。其特点是占有内存少&#xff0c;并发能力强&#xff0c;事实上nginx的并发能力在同类型的网页服务器中表现较好&#xff0c;中国大陆使用nginx的网站有&#xff1a…

nginx的使用

目录 1.何为nginx 2.如何使用 3.关于nginx配置文件 4.nginx三大核心 4.1 反向代理 4.2 负载均衡 4.3 动静分离 4.4 高可用 4.4.1 安装keepalived 代理服务器--使用比较多的为nginx代理服务器。 1.何为nginx Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,其…

MySQL 的索引

文章目录 索引简介普通索引主键索引唯一索引全文索引外键索引复合索引复合索引生效的几种方式复合索引会失效的情况 索引的优点高性能的索引策略独立的列前缀索引和索引的选择性复合索引选择合适的索引列顺序聚簇索引索引的 Btree 结构聚簇索引和非聚簇索引的区别聚簇索引的优点…

[MySQL]索引详解

专栏简介 :MySql数据库从入门到进阶. 题目来源:leetcode,牛客,剑指offer. 创作目标:记录学习MySql学习历程 希望在提升自己的同时,帮助他人,,与大家一起共同进步,互相成长. 学历代表过去,能力代表现在,学习能力代表未来! 1.什么是索引? 当我们想要在书中查找某个知识点时 , …

MySQL:索引特性

索引 0. 预备知识 索引是一个“物美价廉”的特性&#xff0c;用来提高数据库的性能。不需要改程序、调SQL、只需要正确的创建索引&#xff0c;查询速度就能提高成百上千倍&#xff0c;但查询速度的提升也带来了插入、更新、删除速度的下降。 0.1 认识磁盘 MySQL对数据进行增…

MySQL的索引与事务

作者&#xff1a;敲代码の流川枫 博客主页&#xff1a;流川枫的博客 专栏&#xff1a;和我一起学java 语录&#xff1a;Stay hungry stay foolish 给大家推荐一款好用的神器Apifox Postman Swagger Mock JMeter。集接口文档工具、接口Mock工具、接口自动化测试工具、接…

什么是 MySQL 索引?

什么是索引&#xff1f; 假设我们有一张数据表 employee(员工表)&#xff0c;该表有三个字段&#xff08;列&#xff09;,分别是name、age 和address。假设表employee有上万行数据(这公司还真大&#xff09;&#xff0c;现在需要从这个表中查找出所有名字是‘ZhangSan’的雇员信…

MySQL 索引结构

前言 在上一篇 MySQL 索引类型 中&#xff0c;我们已经了解了索引的基本概念以及分类&#xff0c;那么&#xff0c;索引的结构是什么样的&#xff1f;为什么索引可以这么快&#xff1f;这一篇文章将继续探讨索引的实现原理和数据结构&#xff0c;主要介绍 B 树索引和 Hash 索引…

MySQL中索引的使用方法

1. 为什么要加索引&#xff1f; ​一般的应用系统&#xff0c;读写比例在10:1左右&#xff0c;而且插入和一般的更新操作很少出现性能问题&#xff0c;遇到最多的&#xff0c;也是最容易出问题的&#xff0c;还是一些复杂的查询操作&#xff0c;所以查询语句的优化显然是重中之…

MySQL 索引概览

前言 在 SQL 优化中&#xff0c;索引是至关重要的一环&#xff0c;能给查询效率带来质的飞跃&#xff0c;但是索引并不是万能的&#xff0c;不合理的索引设计甚至会拖慢查询效率。本文将详细介绍索引的概览和分类&#xff0c;并讨论使用索引时应该权衡的要素&#xff0c;关于索…

MYSQL的索引和存储引擎

文章目录 MYSQL的索引和存储引擎介绍索引的分类单列索引-普通索引单列索引-唯一索引单列索引-主键索引组合索引全文索引空间索引 索引内部原理剖析索引内部原理-Hash算法索引内部原理-二叉树和二叉平衡树索引内部原理-BTREE树MyISAM存储引擎InnoDB存储引擎 索引的特点索引的创建…

mysql 索引使用与优化

前言 索引对有一定开发经验的同学来说并不陌生,合理使用索引,能大大提升sql查询的性能,可以这么讲,随着业务数据量的不断增长,优化系统的响应速度,很大程度上可以说就是集中在索引的优化上; mysql索引原理 在正式了解与学习mysql索引之前,先对mysql的索引原理再次回…

MySql之索引

1.索引概述 MySql官方对索引的定义为&#xff1a;索引是帮助MySql高效获取数据的数据结构。在数据之外&#xff0c;数据库系统还维护着满足特定查找算法的数据结构&#xff0c;这些数据结构以某种方式引用数据&#xff0c;这样就可以在这些数据结构上实现高级查找算法&#xf…

Mysql 索引

图片来源网络&#xff0c;侵删。图片来源于掘金小册 索引 Mysql 的索引类型有很多种&#xff0c;Hash索引&#xff0c;B树索引&#xff0c;B树索引和全文索引。Mysql有多种存储引擎&#xff0c;每个存储引擎对索引的支持可能会不同。 What Mysql 索引是能改善数据库表随机访…

一文搞懂 MySQL 索引

一文搞懂 MySQL 索引 1、MySQL 索引 简介 1.1、MySQL 索引 是什么&#xff1f; 索引是一个单独的、存储在 磁盘 上的 数据库结构 &#xff0c;包含着对数据表里 所有记录的 引用指针。 1.2、 MySQL 索引 的存储类型有哪些&#xff1f; MySQL中索引的存储类型有两种&#xff0c…

一文搞懂MySQL索引所有知识点(建议收藏)

Mysql索引 索引介绍 索引是什么 官方介绍索引是帮助MySQL高效获取数据的数据结构。更通俗的说&#xff0c;数据库索引好比是一本书前面的目录&#xff0c;能加快数据库的查询速度。 一般来说索引本身也很大&#xff0c;不可能全部存储在内存中&#xff0c;因此索引往往是存储…

python中的%用法

python中%&#xff1a; 1. 求模运算&#xff0c;相当于mod&#xff0c;也就是计算除法的余数&#xff0c;比如5%2就得到1。 2. %还用在python的格式化输出&#xff0c;比如&#xff1a; 说明如下&#xff1a; %[(name)][flags][width].[precision]typecode (name) 为命名 fl…