我在stackoverflow上尝试了类似问题和许多其他问题的解决方案,但它们似乎都没有解决这个问题。默认的niginx"欢迎"即使我配置了 /etc/nginx/passenger.conf 和 /etc/nginx/passenger.conf ,页面也在运行。在我配置 / etc / nginx / sites-enabled / default 之后,通过更改我的rails应用程序的默认路径,我开始收到403 forbidden错误。
这是错误日志。
2017/02/20 06:05:17 [error] 27311#27311: *2 directory index of "/home/deploy/Blog/current/public/" is forbidden, client: 111.93.247.206, server: mydomain.com, request: "GET / HTTP/1.1", host: "35.154.168.57"
我的nginx文件如下。
/etc/nginx/nginx.conf
user deploy;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
# include /etc/nginx/passenger.conf;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
/etc/nginx/passenger.conf
passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.3.1/ruby;
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_ruby /usr/bin/passenger_free_ruby;
的/ etc / nginx的/启用的站点 - /默认
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name mydomain.com;
passenger_enabled on;
rails_env production;
root /home/deploy/Blog/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
权限是:
lrwxrwxrwx 1 root root 34 Feb 20 06:00 /etc/nginx/sites-enabled/default
-rw-r--r-- 1 root root 179 Feb 20 06:35 /etc/nginx/passenger.conf
-rw-r--r-- 1 root root 1608 Feb 20 06:34 /etc/nginx/nginx.conf
请有人告诉我我做错了什么或者我没做什么? 谢谢
答案 0 :(得分:0)
请按照以下步骤操作:
chown -R <nginxuser>:<nginxuser> /home/deploy/Blog/current/public
nginxuser
:运行nginx的用户,可能是以下之一:nginx
,www-data
,root
。
答案 1 :(得分:0)
不确定你到底错过了什么。请在https://www.wiki11.com上与我的设置保持一致。
您的问题即将发生,因为nginx正在尝试将index.html
文件搜索到/home/deploy/apps/mll/current/public
,但该文件中没有该文件。
为了解决这个问题,您需要使用nginx添加乘客。
要遵循的说明。
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
添加Passenger APT存储库
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
安装passenger和nginx
sudo apt-get install -y nginx-extras passenger
现在启动nginx webserver。
sudo service nginx start
接下来,我们需要更新Nginx配置,将Passenger指向我们正在使用的Ruby版本。
sudo vim /etc/nginx/nginx.conf
添加或取消注释
include /etc/nginx/passenger.conf;
保存并关闭nginx.conf。然后打开/etc/nginx/passenger.conf
sudo vim /etc/nginx/passenger.conf
如果您使用的是.rbenv,那么
passenger_ruby /home/deploy/.rbenv/shims/ruby;
或者如果您使用的是rvm,那么
passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.5.0/ruby;
或者,如果您使用的是系统红宝石,那么
passenger_ruby /usr/bin/ruby;
接下来,重启nginx服务器
sudo service nginx restart
将passenger_enabled on;
添加到已启用网站的中心或已启用网站的/ nodeapp文件中。
server {
listen 80;
listen [::]:80;
root /home/deploy/apps/mll/current/public;
index index.html index.htm;
server_name myrailssite.com;
passenger_enabled on;
location / {
try_files $uri $uri/ =404;
}
}
再次重新启动nginx服务器sudo service nginx restart
。希望它应该有用。
有关详细信息,请关注, https://www.phusionpassenger.com/library/install/nginx/install/oss/xenial/