[英]Nginx + Passenger 403 error
我在一個AWS ec2服務器上有一個混合的php / Rails應用程序。 我正在托管Mediawiki安裝,並使用Rails作為其前端。 對於Rails應用程序,我正在使用Passenger作為服務器。 我希望location /
服務Rails應用程序,以及location /w
任何內容或Mediawiki(php5-fpm)提供的任何.php文件。
我曾經有一個可以使用的配置,但是它被黑了,我想對其進行重構。
我當前工作的實施給了我一個403禁止錯誤,當我嘗試訪問的Rails應用程序/
。
我收到的錯誤(來自rails_error.log
): 2017/10/24 20:08:31 [error] 14947#14947: *2 directory index of "/var/www/myapp/public/" is forbidden, client: xx.yy.zz.aa, server: myapp.amazonaws.com, request: "GET / HTTP/1.1", host: "myapp.amazonaws.com"
我現在只能現在/
才能訪問Rails應用程序; 我還沒有專注於php5-fpm配置。
這是我的.conf文件:
網站可用/ myapp.conf:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=mw_cache:10m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80;
listen [::]:80 ipv6only=on default_server;
server_name myapp.com;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
root /var/www/myapp/public;
passenger_enabled on;
location /w {
alias /var/www/mediawiki-1.28.0;
index index.php index.html index.htm;
charset utf-8;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_cache mw_cache;
fastcgi_cache_valid 200 60m;
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:7777;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
error_log /var/log/nginx/mediawiki_error.log;
access_log /var/log/nginx/mediawiki_access.log;
}
error_log /var/log/nginx/rails_error.log;
access_log /var/log/nginx/rails_access.log;
}
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
passenger_root /home/ubuntu/.rvm/gems/ruby-2.3.1@myapp/gems/passenger-5.1.1;
passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.3.1@myapp/wrappers/ruby;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我懷疑它與Passenger的安裝或運行方式有關,或者可能是因為我不是以www-data
而是以ubuntu
身份運行Passenger。
/var/www/myapp/
也由ubuntu擁有,盡管我嘗試使用chown -R www-data /var/www/myapp
和chown -R ubuntu:www-data /var/www/myapp
無濟於事。
有人從這里有任何指針嗎?
謝謝。
您的配置對我有用:至少,如果我以root身份啟動Nginx,則該應用程序已成功啟動(通常如何完成)。
請注意,配置中的user
指令告訴Nginx以哪個用戶身份運行其工作程序,而沒有指定以哪個用戶身份運行“乘客”核心(這是從Nginx最初的繼承來的)。
我的指針如下:
通常,第一件事就是檢查日志。 您的配置聲明了日志文件,但未設置頂級錯誤日志,因此您缺少旅客日志輸出。
要解決此問題,請移動error_log /var/log/nginx/error.log;
到nginx.conf
http {
行的上方。
如果需要,您也可以設置passenger_log_level 7;
(在http
塊中)以獲取非常詳細的日志。
通過更改日志級別並觀察結果,您還可以確保您認為正在使用的配置實際上是您要查詢的URL上使用的配置(即,您可以看到傳入的請求)。
乘客有一些故障排除工具,例如, passenger-status
可用於檢查其是否成功運行。 請注意,您尚未聲明passenger_pre_start網址,因此,只有在第一個請求被路由到Passenger時,Passenger才會啟動您的應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.