【问题标题】:Nginx: Can't open any links on website. Only homepage displayNginx:无法打开网站上的任何链接。仅首页显示
【发布时间】:2019-05-26 13:59:43
【问题描述】:

我有一个在 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 不显示该问题的日志。

【问题讨论】:

  • 当我输入链接时网站 slug 发生变化,但没有显示

标签: php nginx webserver


【解决方案1】:

删除/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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 2012-10-28
    • 2016-07-13
    • 2017-08-27
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多