centos Stream 10安装nginx

一个centos中,lnmp是必备了,启动一个服务

查看官网的文档
https://www.centos.org/centos10/
官网支持的ngixn的版本是nginx 1.26。

New features and enhancements
CentOS Stream 10 includes several notable new features and enhancements.

Kernel
Linux kernel 6.12
Programming languages and compilers
Python 3.12
GCC 14
Go 1.23
Rust 1.82
LLVM 19
Ruby 3.3
Node.js 22
PHP 8.3
OpenJDK 21
Webservers
Apache HTTP Server 2.4.62
nginx 1.26
Databases
PostgreSQL 16
MariaDB 10.11
MySQL 8.4
Valkey 7.2
Desktop technologies
GNOME 47
Qt 6.7
Software management
DNF 4.20
RPM 4.19
Earlier versions of CentOS Stream utilized a technology called modularity to provide optional alternative versions of select software. CentOS Stream 10 will instead use traditional non-modular RPM packages for this purpose.

直接安装 dnf install -y nginx
在这里插入图片描述

dnf install nginx* 查看其他模块
在这里插入图片描述
启动 Nginx 服务:
安装完成后,启动 Nginx 服务并设置为开机自启动:

sudo systemctl start nginx.service
sudo systemctl status nginx.service
sudo systemctl stop nginx.service
sudo systemctl enable nginx.service
sudo systemctl disabled nginx.service

检查 Nginx 状态:
确认 Nginx 已正常运行:

sudo systemctl status nginx

在这里插入图片描述

设置防火墙规则:
如果启用了防火墙,允许 HTTP 和 HTTPS 流量通过:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

验证 Nginx 是否工作正常:
在浏览器中访问服务器的 IP 地址,查看 Nginx 的默认页面:
在这里插入图片描述

http://your_server_ip

在这里插入图片描述

如果看到 Nginx 欢迎页面,说明安装成功。

完成后,您可以在 /etc/nginx/nginx.conf 中配置 Nginx,或者在 /etc/nginx/conf.d/ 目录下添加新的配置文件。

nginx配置文件
在 /etc/nginx/的目录下
在这里插入图片描述
主配置文件nginx.conf

[root@centos10model nginx]# cat nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl;
#        listen       [::]:443 ssl;
#        http2        on;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#    }

}
### 安装 Nginx 并启用 Stream 模块 为了在 CentOS 7 上安装 Nginx 并启用 Stream 模块,可以按照以下方法操作: #### 方法一:通过源码编译安装带有 Stream 模块的 Nginx 由于 Linux 安装 Nginx 默认不带 Stream 模块[^1],因此需要使用相同版本的 Nginx 安装包重新编译来添加此功能。 下载所需版本的 Nginx 压缩包后,在解压缩后的文件夹内运行如下命令来进行配置和编译: ```bash ./configure --prefix=/usr/local/nginx --with-stream --with-http_stub_status_module --with-http_ssl_module make && make install ``` 上述 `--with-stream` 参数用于指定编译时加入 Stream 模块支持;其他参数如 `--with-http_stub_status_module` 和 `--with-http_ssl_module` 则分别用来开启 HTTP 状态页面以及 SSL 功能的支持[^3]。 完成以上步骤之后,启动 Nginx 即可应用新的配置。 #### 配置 Stream 模块 编辑 `/usr/local/nginx/conf/nginx.conf` 文件,向其中添加 stream 块的内容以定义 TCP 或 UDP 流量转发规则。例如: ```nginx stream { upstream backend { server 192.0.2.1:123; server 192.0.2.2:123; } server { listen 12345; proxy_pass backend; } } ``` 这段配置会监听本地端口 12345,并将接收到的数据流转发给上游服务器列表中的节点处理。 保存更改并重启 Nginx 使新设置生效。 #### 方法二:利用第三方 YUM 源快速部署含 Stream 模块的 Nginx 版本 如果不想经历繁琐的手动编译过程,则可以选择添加官方以外的安全可靠的第三方仓库(比如 EPEL),从中获取已经预编译好的包含 Stream 模块在内的 Nginx 软件包进行一键式安装。 先确保已启用了 EPEL 库,接着执行 yum update 更新系统后再尝试安装特定版本号以上的 Nginx 来获得 Stream 模块支持。 ```bash sudo yum-config-manager --add-repo=https://nginx.org/packages/centos/7/noarch/RPMS/ sudo yum clean all sudo yum install nginx ``` 注意这种方法依赖于所选存储库是否提供了集成有 Stream 组件的新版 Nginx 发布物。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值