![]() |
|
Nginx: 403 not found - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88) +---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85) +---- Thread: Nginx: 403 not found (/showthread.php?tid=5734708) Pages: Pages
1
2
|
Nginx: 403 not found - Not Your Average Orange - Oct 10, 2017 Hello, I'm new to the nginx scene. I had it working before, but then I did this. I was trying to move my nginx site specific files to directories like this: var/www/site.com/html Instead of var/www/html So I could host more than one site. I was following this tutorial. I was running as root so I didn't do any permissions stuff. Let's pretend my site is example.com Here's my /etc/nginx/nginx.conf file: https://pastebin.com/a7Y5uC4E /etc/nginx/sites-available/example.com: https://Pastebin.com/R49yHGKV Help would be appreciated :) Also, yes, my path for the root is correct * - datguy.dev - Oct 10, 2017 With Nginx, often more than not, the directory index is not properly defined in the config. Especially, when you go changing directories. Though if you use sudo to mv the files the permissions are broken as well. * - Not Your Average Orange - Oct 10, 2017 (Oct 10, 2017 08:07 PM)datguy.dev Wrote: With Nginx, often more than not, the directory index is not properly defined in the config. Especially, when you go changing directories. Though if you use sudo to mv the files the permissions are broken as well. What do you mean? They lose superuser permissions? How would I reapply those permissions? * - datguy.dev - Oct 10, 2017 (Oct 10, 2017 08:54 PM)Not Your Average Orange Wrote: What do you mean? They lose superuser permissions? How would I reapply those permissions? No. That applies to anything you do under super user. You'll lose permissions of the files if you do so. /etc ... Whereas you should have a user for web based tasks that are not root. If Nignx is running under the www-data user, then your not going to make any progress until that is addressed. Permissions; sudo chown www-data:www-data && sudo chmod -R 755 ${files}. Secondly, for multiple sites you'll need to address the config. Because to locate multiple sites it requires a regex. It's a bit late here. I'd be glad to look into it in the morning. * - Not Your Average Orange - Oct 11, 2017 (Oct 10, 2017 09:29 PM)datguy.dev Wrote: No. That applies to anything you do under super user. You'll lose permissions of the files if you do so. /etc ... Ok, thanks. I will create a user for that doesn't have root perms by default and adjust perms. Maybe I should just reinstall nginx as a regular user? * - datguy.dev - Oct 11, 2017 (Oct 11, 2017 05:18 AM)Not Your Average Orange Wrote: Ok, thanks. I will create a user for that doesn't have root perms by default and adjust perms. It shouldn't matter that you installed nginx as root. In many cases that is normal. There is a difference in the permissions required to install and run nginx and those needed to serve or modify server files. You can run everything nginx as root. But it is not advisable for security and it is potentially destructive for the system as you have experienced with permissions. In your nginx configuration, you have "user www-data;" specified. Therefore, if any of the www related files only have root permissions set, than the user www-data or group will not be able to serve or merely read those files. Does that make sense? You just need to check them with "ls -l" and make sure the www-data user and it's group has access. Afterwards, you can add your normal user account to the www group. Logout and back in for the changes to take affect. The guide you followed is good. Try following it again, but first check the default and working directories of Nginx for your OS. * - Not Your Average Orange - Oct 11, 2017 (Oct 11, 2017 09:32 AM)datguy.dev Wrote: It shouldn't matter that you installed nginx as root. In many cases that is normal. There is a difference in the permissions required to install and run nginx and those needed to serve or modify server files. You can run everything nginx as root. But it is not advisable for security and it is potentially destructive for the system as you have experienced with permissions. Thanks, I think I understand (more) now. I can do this later when I get to my laptop. I have to edit perms for config files as well, right? * - datguy.dev - Oct 11, 2017 (Oct 11, 2017 10:13 AM)Not Your Average Orange Wrote: Thanks, I think I understand (more) now. Nginx should fail to start if it cannot access the config files. By default, the main nginx process runs as root. The children as www-data. Therefore, it would be best to leave them for root. They should at least be readable and writable. (664) Whereas, www-data needs your site's files. It's possible you don't have www users or groups. In that situation, you just need to create them. Here are the defaults: PHP Code * - Not Your Average Orange - Oct 11, 2017 (Oct 11, 2017 11:07 AM)datguy.dev Wrote: Nginx should fail to start if it cannot access the config files. Bad news, I don't believe /etc/nginx/sites-available/example.com exists anymore Here's the output of systemctl: Quote:● nginx.service - A high performance web server and a reverse proxy server I have modified the permissions to the www files as well. * - datguy.dev - Oct 11, 2017 Any luck? Not sure where you stand. In my opinion, nginx is great for a lightweight web server. I've seen it used for some of the best websites on the internet. Although, I have found it to be not as easily to configure as compared to other options when it comes to complex setups such as hosting multiple sites. Apache is overall good. Look into it and see if you have different results. Alternatively, you could also do something as simple a python flask web server and run two instances. * - Not Your Average Orange - Oct 12, 2017 (Oct 11, 2017 11:07 PM)datguy.dev Wrote: Any luck? Not sure where you stand. Well, my files are all in the www-data group, but I'm still getting a 404. I think I'll just go Flask & Apache. This tutorial look good? * - SuckySucky - Oct 12, 2017 just a hunch I have... comment out all PHP include parts in sites-available, restart nginx and see what happens * - Not Your Average Orange - Oct 12, 2017 (Oct 12, 2017 09:18 AM)SuckySucky Wrote: just a hunch I have... comment out all PHP include parts in sites-available, restart nginx and see what happens Thanks for the suggestion, but I go the same thing. I think I'm just going to uninstall NGINX and go with Apache & Flask * - datguy.dev - Oct 12, 2017 (Oct 12, 2017 05:23 AM)Not Your Average Orange Wrote: Well, my files are all in the www-data group, but I'm still getting a 404. I think I'll just go Flask & Apache. This tutorial look good? You went from 403 to 404. 403 Forbidden: meaning something like the requests for resources are not permitted. (Your config's root site directory does not permit access to / or /index.html) Whereas, 404 Not Found, means the requested resource does not exists. (/does_not_exist.html) Their different errors with different causes. I've done apache and flask. But not apache+flask. I'm not really sure of the benefit of doing that, but I'd like to try it personally. I'd just use Apache... The flask app I was talking about is a few lines of code for the app, then you allow firewall traffic through to the port you've specified. Not all that configuring and enabling modules. Not to suggest too much too soon, but you really should consider a plan for how you would migrate your site. It really sucks once you have a complicated and working site, then having to move it to a new machine or host, where your system packages and configs will most likely be broken. Instead, you could develop everything in Docker right now which will produce a "container." (They have basic pre-made containers btw.) Then to migrate, you just ship the container over and that is really it. You can kind of do this with virtualenv, but it is a bit flaky when it comes to directories. * - Not Your Average Orange - Oct 12, 2017 (Oct 12, 2017 01:04 PM)datguy.dev Wrote: You went from 403 to 404. 403 Forbidden: meaning something like the requests for resources are not permitted. (Your config's root site directory does not permit access to / or /index.html) Whereas, 404 Not Found, means the requested resource does not exists. (/does_not_exist.html) Their different errors with different causes. Sorry, I originally got a 404. I kinda wanted to try out flask though. I'll check out docker as well. What do you mean by migrate? As in nameservers and stuff or local files on the vps? Also, I've heard of docker before. What would be the benefit of building in docker if I just have a basic static html site? |