首页 | 人工智能 | 操作系统 | 硬件维修 | 软件编程

centos8如何安装nginx

发布时间:2025-09-07 15:13 | 分类:软件编程 | 作者:admin | 浏览数:28

centos8如何安装nginx

管理员权限请自行加上sudo

dnf install -y nginx

安装完成后

systemctl enable nginx   # 开机启动
systemctl start nginx    # 启动服务
systemctl status nginx   # 查看状态

如无意外,会直接安装成功,接下来查看配置文件

nginx -t

输出了

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

此时我们对配置文件进行编辑

nano /etc/nginx/nginx.conf

每次改动后都需要检查再重载

nginx -t        # 检查语法是否正确
systemctl reload nginx   # 平滑重载配置

windows下典型的配置

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        listen [::]:80;
        server_name  kaspa.run;

        return 301 https://$host$request_uri;
    }

    server {
        listen              443 ssl;
        server_name         localhost;

        ssl_certificate     C:\Certbot\live\kaspa.run\fullchain.pem;
        ssl_certificate_key C:\Certbot\live\kaspa.run\privkey.pem;

        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         HIGH:!aNULL:!MD5;

        location / {
            proxy_pass         http://127.0.0.1:5000;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}

返回首页