Nginx:无法打开网站上的任何链接。仅首页显示

时间:2019-05-24 20:44:20

标签: php nginx webserver

我有一个在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 :(得分:0)

删除/etc/nginx/sites-enabled/*/etc/nginx/sites-enabled/*中的所有默认NGinx文件,如果此配置处于活动状态,则可能会出现问题。

验证它在/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;
    }
}