mk-ned
mk-ned

Reputation: 21

nginx is returning 301 Moved Permanently

I'm apologize if my question is similar to another, but I was unable to find an answer which can help me to solve my problem. so, on my local pc with ubuntu I have installed and configured nginx + wordpress (as described on stackoverflow), everything works fine, but I can't access my website from remote pc. I have created hostname on noip and made all redirections in to the router, but nginx keeps returning 301. any help would be appreciated.

config file:

server {
        listen 80;
        listen [::]:80 default_server ipv6only=on;

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

        server_name localhost;

        location / {
                #try_files $uri $uri/ =404;
                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/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    }

}

curl -I mylocalwebsite.ddns.net

HTTP/1.1 301 Moved Permanently
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 19 Oct 2016 10:36:14 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4.20
Set-Cookie: PHPSESSID=ku8vc501u9srdeqh08cnsdvht6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://localhost/

File: /var/log/nginx/access.log

85.105.338.54 - - [19/Oct/2016:12:38:25 +0200] "HEAD / HTTP/1.1" 301 0 "-" "curl/7.35.0"

Upvotes: 2

Views: 3799

Answers (2)

at-
at-

Reputation: 11

Wordpress have static domain name in their configuration, if you set it to localhost, and access it using IP or another domain name pointed to your wordpress installation, it will redirected to localhost.

Have you tried to set your wordpress domain name in settings, same as your noip domain name? (eg. mylocalwebsite.ddns.net). Check it on your wordpress settings.

Upvotes: 1

alejdg
alejdg

Reputation: 2473

Set mylocalwebsite.ddns.net into your server_name directive and your nginx will be able to respond to your requests to that host.

Upvotes: 0

Related Questions