I have a VPS that was serving static files using Apache. After covering some mileage in Django, I decided to change from Apache to Nginx. I thought it would be a simple matter (eg specifying the root folder for the domain, that settles it). I see that my expectations were unrealistic because now I am getting "404 Not Found" on all paths except the root folder.
mysite.conf:
server {
listen [::]:443 ssl;
listen 443 ssl;
server_name share.mysite.com;
root /var/www/html/share.mysite.com;
location / {
index index.html index.php;
}
}
How do I scale this configuration to serve static files located in different folders in the hierarchy?
1. share.mysite.com/tutorials/a-subject/a.mp4
2. share.mysite.com/tutorials/another-subject/something.jpg
3. share.mysite.com/some-folder/somefile.zip
At the moment, any of the above combinations give me a "404 Not Found", all except " https://share.mysite.com
". Yet, the files are there.
I understand that this may involve the " location
" keyword but I haven't seen a lucid explanation that translates to my case. I seek understanding. Nginx is new to me.
It is because of the rewritten rules. You had them in place when using Apache as most probably WordPress automatically created a .htaccess file and placed the necessary default rewrite rules for the so-called "pretty" URL ( eg accessing /blog /contact etc. ). In order to do that in Nginx, you have to add a few lines in the vhost for your domain there, please refer to the official documentation for that:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.