centos

centos lnmp如何设置域名解析

小樊
31
2025-12-15 18:09:04
栏目: 云计算

CentOS LNMP 域名解析与 Nginx 配置

一、整体思路

二、步骤一 配置 DNS 解析

三、步骤二 配置 Nginx 虚拟主机

server {
    listen 80;
    server_name example.com www.example.com;

    root /var/www/example.com;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    # 根据实际的 PHP-FPM 监听方式二选一
    # 1) Unix socket(常见于 CentOS 的 php-fpm 包)
    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass   unix:/run/php-fpm/www.sock;
    }

    # 2) TCP 端口(如 127.0.0.1:9000)
    # location ~ \.php$ {
    #     include        fastcgi_params;
    #     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #     fastcgi_pass   127.0.0.1:9000;
    # }

    location ~ /\.ht {
        deny all;
    }
}

四、步骤三 防火墙与 HTTPS

五、快速验证与常见问题

0
看了该问题的人还看了