我将 nginx 配置为从我们的服务器为两个虚拟主机提供服务:一个主主机和一个子域主机。主要主机是一个 Rails 应用程序,与乘客一起服务。它按预期工作。
子域主机是一个小的 PHP 应用程序。对此子域进行浏览器请求,它会返回 403(禁止)错误。当对特定文件进行浏览器请求时,它会返回 502(错误网关)错误。
这是 nginx.conf 文件:
#user nobody;
worker_processes 3;
events {
worker_connections 19000;
}
worker_rlimit_nofile 20000;
http {
include mime.types;
default_type application/octet-stream;
passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.18;
passenger_ruby /usr/local/bin/ruby;
sendfile on;
gzip on;
gzip_http_version 1.1;
gzip_disable "msie6";
gzip_vary on;
gzip_comp_level 9;
gzip_static on;
passenger_max_pool_size 6;
passenger_min_instances 1;
passenger_pool_idle_time 10;
# Rails app
server {
listen 80;
server_name .domain.com;
passenger_enabled on;
root /home/ubuntu/rails_app/public;
location ~ ^/assets/ {
expires max;
add_header Cache-Control public;
#add_header Last-Modified "";
#add_header ETag "";
open_file_cache max=1000 inactive=500s;
open_file_cache_valid 600s;
open_file_cache_errors on;
break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# PHP app
server {
listen 80;
server_name sub.domain.com;
root /home/ubuntu/rails_app/sendy;
index index.html index.htm index.php;
if (!-d $uri) {
set $rule_0 1$rule_0;
}
if (!-f $uri) {
set $rule_0 2$rule_0;
}
if ($rule_0 = "21") {
rewrite ^/([a-zA-Z0-9-]+)$ /$1.php last;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
#root html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
#fastcgi_index index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /l {
rewrite ^/l/([a-zA-Z0-9/]+)$ /l.php?i=$1 last;
}
location /t {
rewrite ^/t/([a-zA-Z0-9/]+)$ /t.php?i=$1 last;
}
location /w {
rewrite ^/w/([a-zA-Z0-9/]+)$ /w.php?i=$1 last;
}
location /unsubscribe {
rewrite ^/unsubscribe/(.*)$ /unsubscribe.php?i=$1 last;
}
location /subscribe {
rewrite ^/subscribe/(.*)$ /subscribe.php?i=$1 break;
}
location ~ /\.ht {
deny all;
}
}
}
我认为这是一个权限问题,但我将它们更改为 744、755 甚至 777,但仍然出现相同的错误。
有任何想法吗?