LNMP 是一个集成了 Nginx、MySQL/MariaDB、PHP 的环境,用于搭建网站或 Web 应用。当你说“没有域名”时,我理解为你想了解在没有域名的情况下如何使用 LNMP 环境,或者如何为 LNMP 环境配置域名。
即使没有域名,你仍然可以使用 LNMP 环境在本地或服务器上开发和测试网站。你可以通过 IP 地址或 localhost
来访问你的网站。
<?php
echo "Hello, World!";
?>
编辑 Nginx 配置文件(通常位于 /etc/nginx/sites-available/default
),添加以下内容:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的 PHP 版本调整
}
location ~ /\.ht {
deny all;
}
}
在浏览器中输入 http://your_server_ip
或 http://localhost
,你应该能看到“Hello, World!”的输出。
如果你想为你的 LNMP 环境配置一个域名,你需要:
将 Nginx 配置文件中的 server_name
改为你的域名:
server_name your_domain.com;
sudo systemctl restart nginx
现在,你应该可以通过你的域名访问你的网站了。
希望这些信息能帮助你更好地理解和使用 LNMP 环境。
领取专属 10元无门槛券
手把手带您无忧上云