Editing
Setting up SFTP with Nginx
Jump to navigation
Jump to search
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!
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/</code> # Access via URL: <nowiki>http://your_domain/folder/file.png</nowiki> == Configuration Steps == # Verify Symbolic Link <pre lang="bash"># Check if symbolic link is correct ls -l /home/your_user/public_folder</pre> Expected output: <pre>lrwxrwxrwx 1 your_user your_user 26 Jan 20 15:00 /home/your_user/public_folder -> /usr/share/nginx/html/folder</pre> <ol start="2" style="list-style-type: decimal;"> <li>Check Directory Structure and Permissions</li></ol> <pre lang="bash"># Check website root directory sudo ls -lht /usr/share/nginx/html/ # Check target directory sudo ls -lht /usr/share/nginx/html/folder/</pre> <ol start="3" style="list-style-type: decimal;"> <li>Check Nginx Configuration</li></ol> <pre lang="bash"># Check nginx config sudo nano /etc/nginx/nginx.conf # Or check site config sudo nano /etc/nginx/sites-available/default</pre> Basic nginx configuration should include: <pre lang="nginx">server { listen 80; server_name your_domain; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ =404; } }</pre> <span id="common-issues"></span> == Troubleshooting of Common Issues == * Specific directories return 404 (files exist) * Files uploaded via SFTP not accessible via web * Nginx error log shows permission issues === Solution: Adjust Permission Settings === # Check Nginx Error Log <pre lang="bash">sudo tail /var/log/nginx/error.log</pre> Possible error message: <pre>[crit] stat() "[path]/file.png" failed (13: Permission denied)</pre> <ol start="2" style="list-style-type: decimal;"> <li>Set User Directory Permissions</li></ol> <pre lang="bash"># Ensure user directory is accessible sudo chmod 755 /home/your_user</pre> <ol start="3" style="list-style-type: decimal;"> <li>Set Website Directory Permissions</li></ol> <pre lang="bash"># Ensure website directory is accessible sudo chmod 755 /home/your_user/public_folder</pre> <ol start="4" style="list-style-type: decimal;"> <li>(optional) Set File Permissions</li></ol> <pre lang="bash"># Set file read permissions chmod 644 /usr/share/nginx/html/folder/your_file.png</pre> <span id="permission-details"></span> === Permission Details === * <code>chmod 755</code> (directories): ** Owner: read, write, execute (rwx) ** Group: read and execute (r-x) ** Others: read and execute (r-x) * <code>chmod 644</code> (files): ** Owner: read, write (rw-) ** Group: read (r–) ** Others: read (r–) === Testing and Verification === <ol style="list-style-type: decimal;"> <li><p>Public URL format: <nowiki>http://your_domain/folder/file.png</nowiki></p></li> <li><p>If still inaccessible after configuration:</p> <pre lang="bash"># Reload nginx configuration sudo systemctl reload nginx</pre></li></ol> === Important Notes === # Permission changes take effect immediately, no nginx restart needed # Entire path needs proper execute permissions # New files need correct permissions set # Ensure symbolic links remain intact # Verify files are uploaded to correct location [[Category: Linux]] [[Category: Nginx]]
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)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information