Linux作为Web服务器配置的基础概念主要包括以下几个方面:
以下是一个基本的Linux Web服务器配置示例,使用Nginx和PHP:
sudo apt update
sudo apt install nginx php-fpm
编辑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 index.nginx-debian.html;
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;
}
}
sudo systemctl restart nginx
在 /var/www/html
目录下创建一个 info.php
文件:
<?php
phpinfo();
?>
访问 http://your_server_ip/info.php
应该能看到PHP信息页面。
netstat -tuln
查看端口监听状态。sudo systemctl status nginx
。sudo systemctl status php7.4-fpm
。通过以上步骤,你可以成功地在Linux上配置一个基本的Web服务器。根据具体需求,可能还需要进一步优化和安全加固。
领取专属 10元无门槛券
手把手带您无忧上云