一个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;
# }
}