大网数据广告活动
网站运营与故障问答

Apache not working on AWS Linux after reboot - 301 Response code

· 52CE 我爱测

I have setup an EC2 instance with the Amazon Linux image and installed LAMP and Wordpress as per the Amazon docs. It works fine, serves the default Wordpress page, but as soon as the instance is rebooted the web server no longer …

问题原文

原帖链接 · Brien Crean · CC BY-SA 3.0

I have setup an EC2 instance with the Amazon Linux image and installed LAMP and Wordpress as per the Amazon docs.

It works fine, serves the default Wordpress page, but as soon as the instance is rebooted the web server no longer appears to work. The index page is no longer served. Curling localhost returns empty.

I'm not sure what config is lost on reboot. Apache and MYSQL are running and are setup to run on boot.

When I try and curl http://localhost and I look at the apache access log I see:

::1 - - [17/Jun/2017:00:56:26 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"
::1 - - [17/Jun/2017:00:59:19 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"
::1 - - [17/Jun/2017:00:59:21 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"

Here is my httpd.conf

ServerRoot "/etc/httpd"
Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride All

    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf

Response Headers from curl -v

[ec2-user@ip-x-x-x-x ~]$ curl -v localhost
* Rebuilt URL to: localhost/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.51.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Sat, 17 Jun 2017 23:46:00 GMT
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.21
< X-Pingback: http://ec2-x-x-x-x.x-x-2.x.amazonaws.com/xmlrpc.php
< Location: http://ec2-x-x-x-x.x-x-2.x.amazonaws.com
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
< 
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact

已采纳解答

原帖链接 · Brien Crean · CC BY-SA 3.0

I figured out the issue. When an AWS instance is rebooted, the DNS address changes. As I am using Wordpress, I need to update the siteurl and home url in the MySQL Database for the wordpress site to the new DNS address.

In the pictures below for example localhost should be replaced with the DNS address of the instance. When the instance reboots, this will need to be replaced again with the new DNS address and so on, every time the instance reboots. Really I should have used a static DNS address to save me the pain of this issue :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。