15,068
edits
(Created page with " = Nginx Directory Permissions and Symbolic Link Configuration Guide = == Environment Overview == * Using SFTP to upload files to personal directory * Personal directory linked to website root via symbolic link * Files accessible through public web URL after upload === Example SFTP Upload Process === # Upload file to personal directory: <code>/home/your_user/public_folder/</code> # File automatically reflects in website directory: <code>/usr/share/nginx/html/folder/...") |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
Nginx Directory Permissions and Symbolic Link Configuration Guide | |||
| Line 19: | Line 19: | ||
# Verify Symbolic Link | # Verify Symbolic Link | ||
< | <pre lang="bash"># Check if symbolic link is correct | ||
ls -l /home/your_user/public_folder</ | ls -l /home/your_user/public_folder</pre> | ||
Expected output: | Expected output: | ||
| Line 27: | Line 27: | ||
<li>Check Directory Structure and Permissions</li></ol> | <li>Check Directory Structure and Permissions</li></ol> | ||
< | <pre lang="bash"># Check website root directory | ||
sudo ls -lht /usr/share/nginx/html/ | sudo ls -lht /usr/share/nginx/html/ | ||
# Check target directory | # Check target directory | ||
sudo ls -lht /usr/share/nginx/html/folder/</ | sudo ls -lht /usr/share/nginx/html/folder/</pre> | ||
<ol start="3" style="list-style-type: decimal;"> | <ol start="3" style="list-style-type: decimal;"> | ||
<li>Check Nginx Configuration</li></ol> | <li>Check Nginx Configuration</li></ol> | ||
< | <pre lang="bash"># Check nginx config | ||
sudo nano /etc/nginx/nginx.conf | sudo nano /etc/nginx/nginx.conf | ||
# Or check site config | # Or check site config | ||
sudo nano /etc/nginx/sites-available/default</ | sudo nano /etc/nginx/sites-available/default</pre> | ||
Basic nginx configuration should include: | Basic nginx configuration should include: | ||
< | <pre lang="nginx">server { | ||
listen 80; | listen 80; | ||
server_name your_domain; | server_name your_domain; | ||
| Line 50: | Line 50: | ||
try_files $uri $uri/ =404; | try_files $uri $uri/ =404; | ||
} | } | ||
}</ | }</pre> | ||
<span id="common-issues"></span> | <span id="common-issues"></span> | ||
== Common Issues | == Troubleshooting of Common Issues == | ||
* Specific directories return 404 (files exist) | * Specific directories return 404 (files exist) | ||
| Line 58: | Line 58: | ||
* Nginx error log shows permission issues | * Nginx error log shows permission issues | ||
== Solution: Adjust Permission Settings == | === Solution: Adjust Permission Settings === | ||
# Check Nginx Error Log | # Check Nginx Error Log | ||
< | <pre lang="bash">sudo tail /var/log/nginx/error.log</pre> | ||
Possible error message: | Possible error message: | ||
| Line 69: | Line 69: | ||
<li>Set User Directory Permissions</li></ol> | <li>Set User Directory Permissions</li></ol> | ||
< | <pre lang="bash"># Ensure user directory is accessible | ||
sudo chmod 755 /home/your_user</ | sudo chmod 755 /home/your_user</pre> | ||
<ol start="3" style="list-style-type: decimal;"> | <ol start="3" style="list-style-type: decimal;"> | ||
<li>Set Website Directory Permissions</li></ol> | <li>Set Website Directory Permissions</li></ol> | ||
< | <pre lang="bash"># Ensure website directory is accessible | ||
sudo chmod 755 /home/your_user/public_folder</ | sudo chmod 755 /home/your_user/public_folder</pre> | ||
<ol start="4" style="list-style-type: decimal;"> | <ol start="4" style="list-style-type: decimal;"> | ||
<li>(optional) Set File Permissions</li></ol> | <li>(optional) Set File Permissions</li></ol> | ||
< | <pre lang="bash"># Set file read permissions | ||
chmod 644 /usr/share/nginx/html/folder/your_file.png</ | chmod 644 /usr/share/nginx/html/folder/your_file.png</pre> | ||
<span id="permission-details"></span> | <span id="permission-details"></span> | ||
== Permission Details == | |||
=== Permission Details === | |||
* <code>chmod 755</code> (directories): | * <code>chmod 755</code> (directories): | ||
| Line 93: | Line 94: | ||
** Others: read (r–) | ** Others: read (r–) | ||
== Testing and Verification == | === Testing and Verification === | ||
<ol style="list-style-type: decimal;"> | <ol style="list-style-type: decimal;"> | ||
<li><p>Public URL format: <nowiki>http://your_domain/folder/file.png</nowiki></p></li> | <li><p>Public URL format: <nowiki>http://your_domain/folder/file.png</nowiki></p></li> | ||
<li><p>If still inaccessible after configuration:</p> | <li><p>If still inaccessible after configuration:</p> | ||
< | <pre lang="bash"># Reload nginx configuration | ||
sudo systemctl reload nginx</ | sudo systemctl reload nginx</pre></li></ol> | ||
== Important Notes == | === Important Notes === | ||
# Permission changes take effect immediately, no nginx restart needed | # Permission changes take effect immediately, no nginx restart needed | ||