【问题标题】:Broken Nginx WordPress website after I moved for ubuntu/PHP 7.2 to Debian/PHP 7.3在我将 ubuntu/PHP 7.2 迁移到 Debian/PHP 7.3 后,Nginx WordPress 网站损坏
【发布时间】:2019-11-01 19:29:29
【问题描述】:

我将我的 Nginx WordPress 网站从 Ubuntu/PHP 7.2 移动到 Debian/PHP 7.3,我的博客首页正常,但所有子页面都没有加载

1) 我尝试了 Ubuntu 18.04 和 PHP 7.2 的工作代码,但出现了缺少 fastcgi 参数的错误。

2) 我在 php.ini "cgi.fix_pathinfo=0" 中设置了以下值

3) PHP FPM 正在运行。

sudo service php7.3-fpm status
* php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-06-19 05:41:36 UTC; 15min ago
     Docs: man:php-fpm7.3(8)
 Main PID: 4587 (php-fpm7.3)
   Status: "Processes active: 0, idle: 15, Requests: 28, slow: 0, Traffic: 0req/sec"
    Tasks: 16 (limit: 4915)
   CGroup: /system.slice/php7.3-fpm.service
           |-4587 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
           |-4588 php-fpm: pool www
           |-4589 php-fpm: pool www
           |-4590 php-fpm: pool www
           |-4591 php-fpm: pool www
           |-4592 php-fpm: pool www
           |-4593 php-fpm: pool www
           |-4594 php-fpm: pool www
           |-4595 php-fpm: pool www
           |-4596 php-fpm: pool www
           |-4597 php-fpm: pool www
           |-4598 php-fpm: pool www
           |-4599 php-fpm: pool www
           |-4600 php-fpm: pool www
           |-4601 php-fpm: pool www
           `-4602 php-fpm: pool www

NGINX 正在运行

sudo service nginx status
* nginx.service - nginx - high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-06-19 05:50:28 UTC; 7min ago
     Docs: http://nginx.org/en/docs/
  Process: 4836 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 4840 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 4841 (nginx)
    Tasks: 5 (limit: 4915)
   CGroup: /system.slice/nginx.service
           |-4841 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           |-4842 nginx: worker process
           |-4843 nginx: worker process
           |-4844 nginx: worker process
           `-4845 nginx: worker process

/etc/nginx/nginx.conf 内容

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

error_log /var/log/nginx/error.log;
events {
    worker_connections 1024;
}

http {

    access_log /var/log/nginx/access.log;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;


    client_max_body_size 10M;


    proxy_connect_timeout 1200s;
    proxy_send_timeout 1200s;
    proxy_read_timeout 1200s;
    fastcgi_send_timeout 1200s;
    fastcgi_read_timeout 1200s;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    #access_log /var/log/nginx/access.log;
    #error_log /var/log/nginx/error.log;


    gzip on;
    gzip_disable "msie6";
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_vary on;
    gzip_types
    application/atom+xml
    application/ld+json
    application/manifest+json
    application/rss+xml
    application/vnd.geo+json
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    font/opentype
    image/bmp
    image/x-icon
    text/cache-manifest
    text/vcard
    text/vnd.rim.location.xloc
    text/vtt
    text/x-component
    text/x-cross-domain-policy;

    gzip_proxied any;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;

    gzip_types text/plain text/css text/xml text/javascript 
    application/x-javascript application/xml;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-available/######.com.conf 内容

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 ssl default_server http2;
        listen [::]:443 ssl default_server http2;

        root /www;
        index index.php index.html index.htm;
        server_name fearby.com www.fearby.com;

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

        #SSL
        ssl_certificate /root/.acme.sh/fearby.com/fullchain.cer;
        ssl_certificate_key /root/.acme.sh/fearby.com/fearby.com.key;
        ssl_dhparam /root/.acme.sh/fearby.com/dhparams.pem;

        # SECURITY
        add_header X-Frame-Options sameorigin;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";

        # Force HTTPS
        if ($scheme != "https") {
                return 301 https://$host$request_uri;
        }

        # DENY RULES
        location ~ /\.ht {
                deny all;
        }
        location ~ ^/\.user\.ini {
                deny all;
        }
        location ~ (\.ini) {
                return 403;
        }

        # OTHER RULES

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

        location ~ \.php$ {
                #try_files $uri =404;
                #try_files $uri $uri/ /index.php?q=$uri&$args;
                try_files $uri $uri/ /index.php?$args;

                fastcgi_split_path_info ^(.+?\.php)(/.*)$;

                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }

                fastcgi_index index.php;

                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                fastcgi_param  SCRIPT_FILENAME                   

/wwwroot/$fastcgi_script_name;

                include fastcgi.conf;
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;

       }

        # PERFORMANCE
        fastcgi_param PHP_VALUE "memory_limit = 4096M";


        # DNS
        resolver 1.1.1.1 1.0.0.1 valid=60s;
        resolver_timeout 1m;

        # HEADERS
        location ~* \.(?:ico|css|js|gif|jpe?g|png|js)$ {
                expires 30d;
                add_header Pragma public;
                add_header Cache-Control "public";
        }

}

WordPress 永久链接格式

/article/%postname%/

/etc/nginx/fastcgi.conf 内容

fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param HTTP_PROXY "";
fastcgi_param   QUERY_STRING            $query_string;
fastcgi_param   REQUEST_METHOD          $request_method;
fastcgi_param   CONTENT_TYPE            $content_type;
fastcgi_param   CONTENT_LENGTH          $content_length;
fastcgi_param   PATH_INFO               $fastcgi_path_info;
#Following line causes an Access denied  erorr
# fastcgi_param   PATH_TRANSLATED         /wwwroot$document_root$fastcgi_path_info;
fastcgi_param   REQUEST_URI             $request_uri;
fastcgi_param   DOCUMENT_URI            $document_uri;
fastcgi_param   DOCUMENT_ROOT           $document_root;
fastcgi_param   SERVER_PROTOCOL         $server_protocol;
fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;
fastcgi_param   REMOTE_ADDR             $remote_addr;
fastcgi_param   REMOTE_PORT             $remote_port;
fastcgi_param   SERVER_ADDR             $server_addr;
fastcgi_param   SERVER_PORT             $server_port;
fastcgi_param   SERVER_NAME             $server_name;
fastcgi_param   HTTPS                   $https;

以前更新到php小版本的时候更新sock位置,文件存在

ls -al /var/run/php/php7.3-fpm.sock;
srw-rw---- 1 www-data www-data 0 Jun 19 05:41 /var/run/php/php7.3-fpm.sock

PHP 版本:

PHP 7.3.6-1+0~20190531112735.39+stretch~1.gbp6131b7 (cli)(构建时间:5 月 31 日 2019 11:27:35) (NTS) 版权所有 (c) 1997-2018 PHP 集团 Zend Engine v3.3.6,版权所有 (c) 1998-2018 Zend Technologies 使用 Zend OPcache v7.3.6-1+0~20190531112735.39+stretch~1.gbp6131b7, 版权所有 (c) 1999-2018,由 Zend Technologies 提供

文件的主页加载,但子博客文章(网址:/article/monitoring-cronjobs-on-linux/)报告。

404 Not Found
nginx/1.16.0

我完全不知道如何通过快速 cgi 将子页面加载到我的博客上(root 很好)。

【问题讨论】:

    标签: php wordpress nginx debian fastcgi


    【解决方案1】:

    我通过在 /etc/nginx/sites-available/####.com.conf 中替换它来修复

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

    有了这个

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

    感谢https://www.digitalocean.com/community/questions/nginx-404-error-on-all-wordpress-posts-and-pages-except-homepage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      相关资源
      最近更新 更多