«
ubuntu 使用nginx

时间:2026-1-1    作者:熊永生    分类: linux


ubuntu 使用nginx

下载nginx

apt install nginx -y

创建项目

vim /www/code/xxx.index

<html>
<body>xxxx</body>
</html>

写入伪静态

vim /etc/nginx/sites-available/xx.com

server  {
    listen 80;
    server_name xx.com www.xx.com;
    index index1.html index.html;
    root /www/xx/public; #比如thinkphp只能访问public
    location / {
        try_files $uri $uri/ =404;
    }
}

伪静态使用软连接到 sites-enabled

ln -s /etc/nginx/sites-available/xx.com /etc/nginx/sites-enabled/xx.com

域名写入到hosts

vim /etc/hosts
127.0.0.1 xx.com

重载nginx

nginx -t
service nginx reload

访问

curl xx.com