0

I’ve been running a WordPress site on AWS EC2 instances with Amazon Linux 2 (AL2). Since AL2 will reach End-of-Life in June 2025, I’m migrating the site to Amazon Linux 2023 (AL2023). The deployment process is managed through AWS CodeDeploy, and WordPress installs correctly on the new instance type, just as it did on AL2.

However, I’m encountering an issue with Nginx. While Nginx and all site configuration files are deployed in the expected locations, my website is not accessible from the desired root directory.

Configuration Overview:

In AL2, my site’s root directory configuration is as follows and works correctly:

/var/wordpress/info/DocumentRoot

In AL2023, the Nginx configuration [/etc/nginx/nginx.conf] looks like this:

....
....
include /etc/nginx/conf.d/*.conf;   <-- [ This should load the custom conf file /etc/nginx/conf.d/wordpress_http.conf ]

server {
    listen       80;
    listen       [::]:80;
    server_name  _;

    #root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    error_page 404 /404.html;
    location = /404.html {}

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {}
}

The custom Nginx configuration file located in /etc/nginx/conf.d/wordpress_http.conf is configured to point to the correct root directory, as I did in AL2 which is working fine so far.

Problem: When I test the site with a curl command, the output shows the expected HTML content on AL2. However, running the same curl command on AL2023 results in a 404 error:

curl -i -s http://localhost/info/ja/ -H "Host: xxx.yyy.mysite.com" -H "X-Forwarded-Proto: https"

This is the 404 error I received:

<body>
    <h1><strong>nginx error!</strong></h1>
    <h3>The page you are looking for is not found.</h3>
    ...
</body>

The error in /var/log/nginx/error.log

[root@ip-10-37-253-71 DocumentRoot]# cat /var/log/nginx/error.log  | grep fail
2024/10/25 08:28:36 [error] 50746#50746: *24 open() "/usr/share/nginx/html/info/ja" failed (2: No such file or directory), client: ::1, server: _, request: "GET /info/ja HTTP/1.1", host ....
2024/10/25 12:40:01 [emerg] 91532#91532: open() 

What I’ve Tried So Far:

Reloading and restarting Nginx:

systemctl reload nginx
systemctl restart nginx

Temporarily disabling SELinux:

setenforce 0

Updating file security context for the root directory:

sudo chcon -R -t httpd_sys_content_t /var/wordpress/info/DocumentRoot

None of these steps have resolved the issue. The same deployment and configuration that works on AL2 is not functioning on AL2023.

Why is Nginx not loading my custom configuration on AL2023, even though it works on AL2? What am I missing, and how can I resolve this?

Thanks in advance for any help!

1
  • Maybe you have a bad path one of the files in /etc/nginx/conf.d/*.conf;? Why is root commented out in the nginx.conf? Commented Oct 25, 2024 at 21:23

1 Answer 1

0

Problem solved by commenting out below line in nginx.conf:

listen       [::]:80;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.