Nginx 和 php5-fpm 中的意外重定向

Nginx 和 php5-fpm 中的意外重定向

對網站託管不太有經驗,但我想建立一個 WordPress 網站,但遇到意外重定向的問題,所以我清除了整個 nginx 配置,但仍然得到重定向,不知道如何,因為我找不到無論如何它正在重定向!

這是我所擁有的:

nginx.conf:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
        worker_connections 768;
}

http {

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;


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

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

        gzip off;
        gzip_disable "msie6";

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

我的啟用網站的資料夾中只有一個

sites-enabled# ls
wordpress

server {
        listen   80;

        access_log /var/log/nginx/wordpress-access.log;
        error_log /var/log/nginx/wordpress-error.log;

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

        server_name localhost;

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

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        # pass the PHP scripts to FastCGI server listening on a UNIX socket
        location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
}

fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
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  SCRIPT_NAME        $fastcgi_script_name;
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  HTTPS              $https if_not_empty;

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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

wordpress 資料夾只是預設下載:

/var/www/wordpress# ls -la
total 188
drwxr-xr-x  5 www-data www-data  4096 Oct  6 10:52 .
drwxrwxrwx 54 www-data root      4096 Oct  6 10:52 ..
-rw-r--r--  1 www-data www-data   418 Sep  2 22:33 index.php
-rw-r--r--  1 www-data www-data 19930 Sep  2 22:33 license.txt
-rw-r--r--  1 www-data www-data  7360 Sep 15 09:26 readme.html
-rw-r--r--  1 www-data www-data  4951 Sep  2 22:33 wp-activate.php
drwxr-xr-x  9 www-data www-data  4096 Sep 15 09:58 wp-admin
-rw-r--r--  1 www-data www-data   271 Sep  2 22:33 wp-blog-header.php
-rw-r--r--  1 www-data www-data  5007 Sep  2 22:33 wp-comments-post.php
-rw-r--r--  1 www-data www-data  2749 Oct  6 10:54 wp-config.php
-rw-r--r--  1 www-data www-data  2764 Sep  2 22:33 wp-config-sample.php
drwxr-xr-x  4 www-data www-data  4096 Sep 15 09:58 wp-content
-rw-r--r--  1 www-data www-data  3286 Sep  2 22:33 wp-cron.php
drwxr-xr-x 12 www-data www-data  4096 Sep 15 09:58 wp-includes
-rw-r--r--  1 www-data www-data  2380 Sep  2 22:33 wp-links-opml.php
-rw-r--r--  1 www-data www-data  3123 Sep  2 22:33 wp-load.php
-rw-r--r--  1 www-data www-data 34669 Sep  2 22:33 wp-login.php
-rw-r--r--  1 www-data www-data  8252 Sep  2 22:33 wp-mail.php
-rw-r--r--  1 www-data www-data 11062 Sep  2 22:33 wp-settings.php
-rw-r--r--  1 www-data www-data 25124 Sep  2 22:33 wp-signup.php
-rw-r--r--  1 www-data www-data  4035 Sep  2 22:33 wp-trackback.php
-rw-r--r--  1 www-data www-data  3055 Sep  2 22:33 xmlrpc.php
root@DMZ-Server:/var/www/wordpress# nano index.html

nginx 似乎正在正確的連接埠上運行,一切正常:

netstat -apn | grep 80
tcp        0      0 0.0.0.0:80    0.0.0.0:*    LISTEN      20612/nginx

然而,當我在本機主機中造訪該網站時,這就是任何日誌中顯示的全部內容(在 wordpress-access.log 中)。這只是有時會出現錯誤(這真的很奇怪):

127.0.0.1 - - [06/Oct/2015:11:51:17 -0500] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.2.0"

然後它強迫將我重定向到 localhost:8090。我還是不知道為什麼。 php5-fpm 日誌中也沒有顯示任何異常情況。我檢查了 IPTables -nat -L 以查看是否顯示任何內容,但什麼都沒有出現。有任何想法嗎?

答案1

抱歉,顯然我很久以前就已經在另一台電腦上設定了 WordPress 資料庫,因此這個 WordPress 實例使用的是已經配置的資料庫,該資料庫在資料庫中設定了連接埠重定向。一旦我清除了資料庫,確切的問題就得到了解決。 (仍然無法僅在http上運行wordpress,由於某種原因它強制使用https,但我確信我可以解決這個問題)。

相關內容