Hello i setup my first webserver for rails but when i copy rails app and run nginx server, im getting 403 error in browser and error.log says that directory index is forbidden.. the error is solved when i create index.html in public folder in rails app but why rails is not started ? (server was compilled with passenger) and bundle install inside rails app works. thank you.
/opt/nginx/conf/nginx.conf
http {
passenger_root /home/lukas/.rvm/gems/ruby-1.9.3-p448#rails3/gems/passenger-4.0.14;
passenger_ruby /home/lukas/.rvm/wrappers/ruby-1.9.3-p448#rails3/ruby;
include /opt/nginx/conf.d/*.conf;
...
}
/opt/nginx/conf.d/default.conf
server {
listen *:80;
server_name hostname.org www.hostname.org
passenger_enabled on;
rails_env production;
root /var/www/default/public;
error_log /opt/nginx/logs/vhosts/default/error.log;
access_log /opt/nginx/logs/vhosts/default/access.log combined;
}
folder permissions
lukas#webserver:/var/www$ ls -al
drwxrwxr-x 13 lukas lukas 4096 Aug 30 12:26 default
im starting nginx with
sudo /etc/nginx/sbin/nginx
/opt/nginx/logs/vhosts/default/error.log
2013/08/30 12:48:08 [error] 32643#0: *1 directory index of "/var/www/default/public/" is forbidden, client: xx.xx.xx.xx, server: ...
Nginx needs to have read permissions for the file as well as execute permissions for every hierarchical parent directory of the file to chdir to it and also Sometimes, the index directive does not contain the desired directory index.
Related
I have a wordpress website. I want to make some files available only via a username/password authentication. For this I simply want to use the nginx authentication. So I did the following steps.
1) Create a .htpasswd file with an encrypted password for user asdf: sudo htpasswd -c /etc/nginx/.htpasswd asdf
I am then prompted to enter and re-enter the password. The file is created and has the following permission rights:
-rw-r--r-- 1 root root 43 Jan 26 13:39 .htpasswd
2) I change the nginx configuration by adding the following block:
location /targetfolder/pdf {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
/targetfolder/pdf is the location where the files reside that should be password protected.
3) I then restart nginx: sudo service nginx restart.
Then I browse to the folder and am prompted for the credentials. After entering the correct credentials I get an 403 forbidden nginx error message.
The error in error.log says:
2020/01/26 13:45:21 [error] 29853#0: *3 directory index of "/var/www//targetfolder/pdf/" is forbidden, client: xx.xxx.xxx.xxx, server: example.com, request: "GET /targetfolder/pdf/ HTTP/1.1", host: "example.com"
What am I doing wrong? I have already tried different solutions such a trying different locations for .htpasswd, setting the index-files in the nginx-configuration etc. Could it have something to do with wordpress? Could it be that something goes wrong when encrypting/decrypting the entered password?
FWIW, nginx is running with the root user. the command ps aux | grep nginx returns.
root 29849 0.0 0.1 91836 3060 ? Ss 13:44 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
Can answer my own question. The configuration basically was correct, however, the following line in the error.log indicated my error:
2020/01/26 14:56:13 [error] 30373#0: *54 directory index of "/targetfolder/pdf/" is forbidden, client: 80.110.88.251, server: example.com, request: "GET /pdf/ HTTP/1.1", host: "example.com"
This means that per default nginx seems not to allow directory listings (which is a good thing). So I just had to set Autoindex on for my targetfolder resulting in the following configuration of the site/location:
location /targetfolder/pdf {
autoindex on; #added
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
I'm trying to run rails app using nginx and unicorn based on Ryan Bates railcast (it's brand new rails new testapp).
So first step I want to test nginx only, no unicorn - just to work on index.html in public/. I point it to my testapp direcory, and get "index of "/var/www/testapp" is forbidden" error (I even set it all for 777 and got the same error)
My username: deployer, nginx: worker process user is www-data.
In my sites-enabled for my testapp I have symlink to /var/www/testapp/config/nginx.conf
:
server {
listen 80;
server_name beta.sitename.pl;
root /var/www/testapp;
}
Owner of www/ and all it's files and subdirectories is deployer and group www-data, all is set to 775.
Any idea where is the problem?
Try setting directory index properly, for example:
index index.html default.html index.php;
in your location block or use autoindex on option.
More info here
I am new to setting up my own server with nginx so forgive any ignorance. I may have just been using the wrong search terms to find the answers to my questions.
Anyway, I am using Rails 3, Nginx, and Unicorn at the moment on a VPS on rackspace. In my rails app I have about 500mb of files in public/ and I would like to use Nginx to serve these. Typically this is just:
server {
listen 80 default deferred;
# server_name example.com;
root /home/<my_user>/apps/<my_app>/current/public;
...
}
I can make this work if I add the 500mb in public to the git repo and then deploy with capistrano, but I don't want all of those files in my git repo. It makes no sense to store them there, but if I remove them then I have to manually go upload them to my public folder on the server every time I deploy.
Is there a way to make Nginx point to a second folder of assets for it to server? I tried the following:
location /static {
gzip on;
alias /home/deployer/static/;
}
I haven't had any luck getting this to work (trying to access the files via url.com/static/...) Anyone know what I am doing wrong?
Side note: all of the shown code is in my config/nginx.conf file and it SHOULD be overriding the settings via this line in my deploy.rb:
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
location /static/ {
root /home/deployer;
}
http://nginx.org/r/alias
http://nginx.org/r/root
Folks
I Am trying to set up ruby on rails 3.2.3 with passenger 3.0.12 and nginx 1.2. I have followed instructions to compile nginx with passenger module. Following is my nginx configuration. When I try to go to the root page (using curl localhost), it gives me 403 forbidden error. It does not seem to pass the request on to passenger. Let me know if I am missing something simple. Thank you,
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12;
passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-1.9.3-p194/ruby;
rails_env development;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
passenger_enabled on;
location / {
root /home/ubuntu/rails/myapp/public;
}
}
}
EDIT
If I do the following:
1) create a new app - dummy
2) Change the config.ru to print 'hello world'
3) change the root to point to dummy app's public directory
Then the error goes away.
Also, if I create a brand new rails app, I am able to access the default rails app page. I have also tried to make directory perms 777 for the entire myapp directory structure. No joy.
Solved it.The passenger_enabled clause has to be moved to within the location block.
What I've tried:
php.ini
log_errors = On
error_log = /etc/httpd/logs/php_error.log
httpd.conf
php_value error_log /etc/httpd/logs/php_error.log
I've tried these in different combinations, stopped and started httpd and verified that these settings are recognized in phpinfo(), but it all still goes to the apache error.log file.
How can I get php error_log() output in a separate file from the httpd error.log file?
PHP 5.3.5
Server version: Apache/2.2.3
Thanks
... The file should be writable by the web server's user ...
Source: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log
try to change the the log directory to e.g. /var/log/php/my_php_errors.log
make sure the folder exists:
mkdir /var/log/php/
/etc/... is usually used not for logging use some folder/file in /var/log/... instead
Is there a reason you're using two different log paths?
error_log = /etc/httpd/logs/php_error.log
php_value error_log /etc/php/logs/php_error.log
^^^^
Does /etc/php/logs exist?