Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Troubleshooting of nginx errors
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Troubleshooting of Nginx Errors == === Nginx and Apache Server Conflict Troubleshooting Guide === '''Problem Overview''' When trying to access files through Nginx (such as {{kbd | key=<nowiki>http://example.com/example_folder/example.png</nowiki>}}), you encounter a 404 error, even though the file definitely exists on the server. '''Environment Overview''' * Operating System: Debian * Web Server: Nginx and Apache installed simultaneously * File Path: <code>/usr/share/nginx/html/example_folder/example.png</code> '''Investigation of Issue''' 1. Verify File Existence <pre lang="bash"> = Confirm the file exists in the correct location on the server = ls -lht /usr/share/nginx/html/example_folder/ </pre> Output shows the file exists: <pre> total 628K * rw-r--r-- 1 username username 501K Apr 18 12:14 example.png </pre> 2. Check And Fix Nginx Configuration Check the Nginx configuration file syntax for any errors <pre lang="bash"> sudo nginx -t </pre> 3. Try Restarting Nginx <pre lang="bash"> sudo systemctl restart nginx </pre> Encountered error: <pre> Job for nginx.service failed because the control process exited with error code. </pre> 4. Diagnose Startup Failure Reason Check service status: <pre lang="bash"> systemctl status nginx.service </pre> Error message: <pre> nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) </pre> 5. Check Port Usage <pre lang="bash"> sudo lsof -i :80 </pre> Output shows Apache is using port 80: <pre> COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 1447 root 4u IPv6 25157 0t0 TCP *:http (LISTEN) apache2 72832 www-data 4u IPv6 25157 0t0 TCP *:http (LISTEN) ... </pre> '''Solutions''' Disable Apache, Enable Nginx <pre lang="bash"> # Stop and disable Apache sudo systemctl stop apache2 sudo systemctl disable apache2 # Start and enable Nginx sudo systemctl start nginx sudo systemctl enable nginx </pre> Verify Configuration After restarting Nginx, try accessing your file: <pre> http://example.com/example_folder/example.png </pre> === Common Permission Issues === If you still have access problems, check file permissions: Ensure Nginx user can access the directory <pre lang="bash"> sudo chown -R www-data:www-data /usr/share/nginx/html/example_folder sudo chmod -R 755 /usr/share/nginx/html/example_folder </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)