惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
IT之家
IT之家
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
博客园 - 【当耐特】
The Cloudflare Blog
宝玉的分享
宝玉的分享
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
Visual Studio Blog
小众软件
小众软件
博客园_首页
Last Week in AI
Last Week in AI
J
Java Code Geeks
V
V2EX
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
博客园 - 司徒正美
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
F
Full Disclosure
B
Blog
H
Help Net Security
C
Check Point Blog
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
L
LangChain Blog
P
Proofpoint News Feed
D
Docker
Microsoft Security Blog
Microsoft Security Blog

博客园 - 心冰之海

最佳的免费Linux杀毒软件有哪些 源代码管理工具TFS简介 信息安全岗位技能提升路径图 IDEA,mysql,mysql workbeanch 新手开发环境搭建教程 JVM-性能优化工具 MAT SQL SERVER死锁查询,死锁分析,解锁,查询占用 Spring Boot热更新技巧:节省90%重启时间 Java spring boot 银河麒麟系统V10安装mysql5.7 Keycloak 安装 使用 DBeaver 企业版将 SQL Server 数据库迁移至达梦 DM8 DBeaver 23.2 AI 智能体 DeepSeek本地化部署超简单,比装个office还简单 数据可视化分析平台 DataEase .NET 6应用程序适配国产银河麒麟V10系统随记 Linux上使用docker部署.net8项目详细教程 nginxUI 安装及学习 AI编程
Nginx的安装并配置web服务
心冰之海 · 2025-01-16 · via 博客园 - 心冰之海

nginx安装

步骤:安装GCC编译器等工具

一、安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

二、首先要安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

1、下载 PCRE 安装包

下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
如果没有wget , 则需要安装wget yum -y install wget wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、解压安装包:

tar zxvf pcre-8.35.tar.gz

3、进入安装包目录

4、编译安装

 ./configure
make && make install

5、查看pcre版本

步骤yum安装Nginx

第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo:

cd /etc/yum.repos.d/

vim nginx.repo    直接用vim编写文件  会自己创建

填写如下内容:

复制代码

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

复制代码

保存,则会产生一个/etc/yum.repos.d/nginx.repo文件。

下面直接执行如下指令即可自动安装好Nginx:

yum install nginx -y

systemctl start nginx //记得启动nginx

现在Nginx已经启动了,直接访问服务器就能看到Nginx欢迎页面了的。

nginx配置文件实现web服务

nginx.conf文件结构

复制代码

...              #全局块

events {         #events块
   ...}

http      #http块{
    ...   #http全局块
    server        #server块
    { 
        ...       #server全局块
        location [PATTERN]   #location块
        {
            ...
        }
        location [PATTERN] 
        {
            ...
        }
    }
    server
    {
      ...
    }
    ...     #http全局块}

复制代码

1、全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。

2、events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。

3、http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。

4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。

5、location块:配置请求的路由,以及各种页面的处理情况。 

进入配置文件

[root@localhost ~]# vi /etc/nginx/nginx.conf 

复制代码

      2 user  nginx;
      3 worker_processes  1;
      4 
      5 error_log  /var/log/nginx/error.log warn;
      6 pid        /var/run/nginx.pid;
      7 
      8 
      9 events {
     10     worker_connections  1024;
     11 }
     12 
     13 
     14 http {
     15     include       /etc/nginx/mime.types;
     16     default_type  application/octet-stream;
     17 
     18     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     19                       '$status $body_bytes_sent "$http_referer" '
     20                       '"$http_user_agent" "$http_x_forwarded_for"';
     21 
     22     access_log  /var/log/nginx/access.log  main;
     23 
     24     sendfile        on;
     25     #tcp_nopush     on;
     26 
     27     keepalive_timeout  65;
     28 
     29     #gzip  on;
     30      server {
     31          listen 80;
     32          server_name 192.168.65.10;   //改成自己的IP
     33          location / {
     34          root /home/web/html;         //自身加载的目录
     35          index choose.html;     //显示的主页 , 且每个指令都必须要有  ;  结束 
     36 }
     37 }
     38     include /etc/nginx/conf.d/*.conf;

复制代码

修改好配置文件之后,可以使用nginx -t 校验文件是否语法合法。然后重启!

1) nginx -t :测试配置文件是否有语法错误

2) nginx -s reopen:重启Nginx

3) nginx -s reload:重新加载Nginx配置文件,然后以优雅的方式重启Nginx

4) nginx -s stop:强制停止Nginx服务

5) nginx -s quit:优雅地停止Nginx服务(即处理完所有请求后再停止服务)

注如果出现403则要以下操作:

复制代码

[root@localhost ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled     //关闭selinux重新启动系统    然后查看nginx的状态,如果关闭则重新启动nginx 即systemctl start nginx,并重新加载配置文件,即nginx -s reload
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

复制代码

在浏览器的地址栏上打上配置文件的IP进入首页