Host machine cannot access nginx virtual hosts on the guest machine - windows

Question: how to create simple nginx config that will read folders structure as domains (test.local, myblog.local) and shows the page from this folders, including PHP?
Information:
Windows 10 x64 build
Vagrant 1.9.5
VirtualBox 5.0.22 (latest)
Guest OS: Ubuntu Xenial x64 latest
So, i want to create simple nginx config, that will recreate folder structure. See
my config file on pastebin.
Also here is a Vagrantfile config, which use SMB to mount a folder.
The structure of folders:
├───devhost.local
│ ├───log
│ └───public
│ index.html
│ index.php
│
└───test.local
├───log
└───public
index.html
The rights for files and folders for devhost:
ubuntu#ubuntu-xenial:~$ ls -la /var/www/html/devhost.local/
total 4
drwxr-xr-x 2 ubuntu www-data 0 Jun 7 11:17 .
drwxr-xr-x 2 ubuntu www-data 4096 Jun 7 12:44 ..
drwxr-xr-x 2 ubuntu www-data 0 Jun 7 11:17 log
drwxr-xr-x 2 ubuntu www-data 0 Jun 6 14:13 public
My hosts file in Windows:
192.168.33.10 devhost.local
So, when i have default config in my sites-enabled folder i can open guest machine through 192.168.33.10 and i see html page of nginx, but when i remove this default config and enable my wildcard config (see link my config file) so i cannot access my domains. The sudo nginx -t says that everything is ok, also i tried to restart my guest machine, reload/restart nginx service. Also, i disable Windows 10 Firewall (i dont know if its disabled fully, but says that its disabled). Also, the log files is empty and even not created, both access log and error log.
Where is my mistake? If need more information, please, ask me, i will give.
Thanks a lot!

following nginx setup should help.
server {
listen 80 default_server;
root /var/www/html/$host;
index index.html index.php;
location ~ \.php {
# ... fastcgi details
}
}

I found the solution.
First of all, when i keep only one file with config, my nginx doesnt listen port 80, i check sudo netstat -ntlp | grep LISTEN but there wasnt port 80. So i Google, and found another question on stackoverflow (see link at the end).
Solution: recreate the simlink to my file with config, after that when i run sudo nginx -t i see a few errors. So its seems that before this files was empty or something like that, but i didnt notice this because i edit file directly in sites-available folder.
Thanks to everybody!
This question helps me to solve the problem: nginx not listening to port 80

Related

How to set up /etc/hosts to access a subfolder like it's a root folder (on a Mac)

I am setting up a new machine. I have it configured to use a Sites folder and localhost to access it. Using Apache, everything installed via Homebrew.
Sites folder
site1
site2
In the browser
localhost/site1/index.html
localhost/site2/index.html
That part works fine.
The problem is that site1 and site2 think localhost is the root folder (which it is) but I want them to think localhost/site1 and localhost/site2 are the root folders for those sites.
Is this something I can do with /etc/hosts or some other trickery?
It turns out this is a combination of /etc/hosts and Apache VirtualHosts. Here are the steps I took:
Establish the directories where you want to serve them from (this will become your DocumentRoot). In my case /Users/myusername/Sites/site1
Edit your /etc/hosts file to include your new "domain name" (this will become your ServerName). In my case site1.com
127.0.0.1 site1.com
::site1.com
Create an Apache Virtual Host ... there are different ways to go about this, but I used Homebrew to install Apache, so for me, there is a file here: /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf. I copied the examples provided using DocumentRoot and ServerName as noted above.
Update this file /opt/homebrew/etc/httpd/httpd.conf to uncomment this line
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
Restart Apache

Laradock - Localhost refused to connect on Windows 10 using Nginx

I have setup a laradock app on my local machine. I have followed the instructions as provided:
http://laradock.io/
In addition to that as I am on Windows 10, and using Docker toolbox, I have shared my folder with the laradock's workspace. That's working fine as I can see my app's folders inside the workspace when I run the following command
docker-compose exec workspace bash
I have also added a host entry inside my hosts file on windows.
127.0.0.1 localhost
But nothing works. I get a response 'localhost refused to connect'. Even css files inside public folder are not accessible
You should checkout the nginx/sites folder inside your laradock folder. Check the root path inside default.conf - root /var/www/public; should correspond to where your project /public folder actually is inside workspace.
I personally use laradock for many projects and create multiple .conf files that correspond to my sites name like myproject1.test - myproject1.conf and my file structure is like that:
/laradock
/myproject1
/myproject2
hosts file:
127.0.0.1 myproject1.test
127.0.0.1 myproject2.test
myproject1.conf inside nginx/sites:
...
server_name myproject1.test;
root /var/www/myproject1/public;
...
Hope that helps

Vagrant synced folder using NFS wrong permissions

Trying to use the NFS plugin with a synced folder in Vagrant, and it is working, except that in the guest (VM) the permissions are wrong:
-rw-r--r-- 1 501 dialout 0 Jan 20 00:51 a
-rw-r--r-- 1 501 dialout 0 Jan 20 00:51 foo
I tried setting up the uid and gid according to the Vagrant documentation in the Vagrantfile:
config.nfs.map_uid = 1001
config.nfs.map_gid = 1001
Which I was hoping would use the correct user/group in the guest, but it is still using 501 and dialout.
Any ideas?
This worked for me on a MacOS Catalina host and Ubuntu 18.04 guest (Vagrant 2.2.9, VirtualBox 6.1.12):
opts = {
type: 'nfs',
linux__nfs_options: ['no_root_squash'],
map_uid: 0,
map_gid: 0
}
config.vm.synced_folder '.', '/var/www/project', opts
You can then chown and chmod as usual:
$ sudo chown -R vagrant:vagrant /var/www/project
$ sudo chmod -R 774 /var/www/project/logs
ATTENTION: no_root_squash is fine for development environments, but DON'T use it for production. It allows remote root users to change any file in the shared file system.
Another option might be to use the vagrant-bindfs plugin. But I didn't feel like installing and configuring an extra plugin for this.
I had the same issue. It started after I've upgraded my MacOS to mcOS Sierra version 10.12.1. The trick that worked for me was to set/force the owner and group to the 'vagrant' user in Vagrantfile like this:
config.vm.synced_folder "/users/myuser/src/", "/home/vagrant/src/", owner: "vagrant", group: "vagrant"
I also had to remove the 'nfs: true' setting that was previously there in the Vagrantfile.

Writing permission with VSFTPD and Centos 6.2

I have a server with centos 6.2 with httpd and vsftpd.
I have few web site in /var/www and i want to add a ftp user for each site.
My user1 have a directory in /home/user1 and can read/write to it folder from ftp. (it's the user i use to ssh and almost everything)
I made user2 with it's home /var/www/site2 and /bin/nologin (because i want it to be just a ftp user)
I can log in the FTP with the user2 and download file, but i can't upload file or mkdir...
The permission are "drwxrwxrwx. 2 user2 user2 4096 Aug 21 14:35 ." (the 777 was just for testing...)
My vsftpd.conf is :
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=NO
log_ftp_protocol=YES
chroot_local_user=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
banner_file=/etc/vsftpd/banner
My iptables is currently stop for testing, so it isn't my firewall either...
Thank in advance for your help
Sorry, wrong site my bad...
I post my question at Serverfault and got an answer, so here is the link!
https://serverfault.com/questions/532949/writing-permission-with-vsftpd-and-centos-6-2

403 Forbidden on Apache (CentOS) Server as GUEST On Windows 7

These are my VM setup:
HOST: windows 7 ultimate 32bit
GUEST: CentOs 6.3 i386
Virtualization soft: Oracle virtualBox 4.1.22
Networking: NAT -> (PORT FORWARD: HOST:8080 => GUEST:80)
Shared Folder: centos
all the project files goes into shared folder and for each project file a virtualhost conf file is created in /etc/httpd/conf.d/ like /etc/httpd/conf.d/$domain
I wasn't able to see anything in my browser before disabling both windows firewall and iptables in centos after that if i type for example: http://www.$domain:8080/ all i see is:
Forbidden
You don't have permission to access / on this server.
Apache/2.2.15 (CentOS) Server at www.$domain.com Port 8080
A sample Virtual Host conf file:
<VirtualHost *:80>
#General
DocumentRoot /media/sf_centos/path/to/public_html
ServerAdmin webmaster#$domain
ServerName www.$domain
ServerAlias $domain *.$domain
#Logging
ErrorLog /var/log/httpd/$domain-error.log
CustomLog /var/log/httpd/$domain-access.log combined
#mod rewrite
RewriteEngine On
RewriteLog /var/log/httpd/$domain-rewrite.log
RewriteLogLevel 0
</VirtualHost>
centos shared folder is availabe to guest at /media/sf_centos
These are file permissons for sf_centos:
drwxrwx--- root vboxsf
vboxsf group includes: apache and root
So these are my questions:
1- How to solve Forbidden Problem?
2- How to setup both host and guest firewalls?
3- How can improve this development environment to simulate production environment as much as possible specially security improvements?
For #1/2: This is a permissions issue due to the auto-mounting method that VirtualBox uses. Instead of auto-mounting you have to mount it manually.
The post by suomynona (3rd reply) has some step-by-step instructions on resolving this issue:
https://forums.virtualbox.org/viewtopic.php?f=3&t=38891#p179152
As for #3, a standard practice is to have a staging server that mimics production as closely as possible (same OS, same updates, versions, etc). That will allow you to deploy from your local development environment for integration testing before you deploy to production. Sometimes we'll even set up our dev VM's to use the same OS as production for more complex projects where version/compatibility issues may cause headaches.

Resources