nginx配置不起作用

时间:2020-02-27 09:49:54

标签: nginx

我正在尝试设置基本的nginx服务器。通常我不使用nginx,遇到了一些我无法解决的问题。

我有一个debain服务器,其中安装了所有必需的东西(例如php,mariadb,ufw等),并且我想像这样运行我的网站:

xxx.xxx.xxx.xxx                 ->      /var/www/
http(s)://(www).lechner.io      ->      /var/www/domains/lechnerio/

我想要https和http以及带www的域,但都不要指向文件夹/var/www/domains/lechnerio,而IP地址则指向/var/www/

首先,只有:80开始工作。

我有以下配置设置:

server {
        listen 80;
        listen [::]:80;

        root /var/www/doamins/lechnerio;
        index index.php index.html index.htm;

        server_name lechner.io;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/etc/php/7.3/fpm/php-fpm.conf;
        }
}

但是,当我现在尝试访问IP时,将显示nginx欢迎站点。当我通过域访问它时,即使我重新加载了所有内容,它也会显示/var/www/中的文件。 nginx -t正在工作。从/etc/nginx/sites-available/lechnerio/etc/nginx/sites-enabled/

的链接

任何输入都非常欢迎!

1 个答案:

答案 0 :(得分:0)

尝试关注

server {
        listen 80;
        listen [::]:80;

        root /var/www/doamins/lechnerio;
        index index.php index.html index.htm;

        server_name lechner.io www.lechner.io;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/etc/php/7.3/fpm/php-fpm.conf;
        }
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/;
        index index.html index.htm;

        server_name _; # everything else

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