Nginx: не могу открыть ссылки на сайте. Отображение только домашней страницы - PullRequest
0 голосов
/ 24 мая 2019

У меня есть сайт, работающий на Nginx.У меня проблема, потому что домашняя страница загружается нормально, но я не могу получить доступ к любой другой ссылке через домашнюю страницу - ничего не происходит.

    server {
  server_name example.com www.example.com;
  root /usr/share/nginx/example.com;
  index index.php index.html index.htm;

 location / {
                try_files $uri $uri/ /index.php$args;
        }

        location ~ \.php$ {
               fastcgi_pass   127.0.0.1:9000;
               fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/example.com$fastcgi_script_name;
               include        fastcgi_params;
            }

        location ~ /\.ht {
                deny all;
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example/com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

Nginx не показывает ЛОГИ по этой проблеме.

1 Ответ

0 голосов
/ 25 мая 2019

Удалите все файлы NGinx по умолчанию в /etc/nginx/sites-enabled/* или /etc/nginx/sites-enabled/*, у вас могут возникнуть проблемы, если эта конфигурация активна.

Убедитесь, что в /etc/nginx/nginx.conf есть следующая строка:

include /etc/nginx/conf.d/*.conf; 

Создайте новый файл /etc/nginx/conf.d/exemple.com.conf и попробуйте:

server {
    listen 80;

    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    root /usr/share/nginx/example.com;

    access_log /var/log/nginx/ssl_exemple.com.log;
    error_log /var/log/nginx/error_ssl_exemple.com.log;

    index index.html index.htm index.php;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example/com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    # Not found this on disk?
    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
        break;
    }

    location / {
        index index.php;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    # Pass the PHP scripts to FastCGI server
    # listening on 127.0.0.1:9000
    location ~ \.php$ {
        # fastcgi_pass   unix:/tmp/php-fastcgi.sock;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_intercept_errors on; # to support 404s for PHP files not found
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout 1800;
        include fastcgi_params;
    }

    # Static files.
    # Set expire headers, Turn off access log
    location ~* \favicon.ico$ {
        access_log off;
        expires 1d;
        add_header Cache-Control public;
    }

    location ~ ^/(img|cjs|ccss)/ {
        access_log off;
        expires 7d;
        add_header Cache-Control public;
    }

    # Deny access to .htaccess files,
    # git & svn repositories, etc
    location ~ /(\.ht|\.git|\.svn) {
        deny  all;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...