2015-09-13 62 views
2

我試圖配置nginx,以便我可以運行一個主要網站/,然後運行一個新的Laravel站點/ myapp。我已經擺脫了應用程序本身(公用文件夾部分)中/ myapp/public的需要,所以我需要的是正確提供該/ myapp文件夾。現在我可以正確地訪問主頁,但是/ myapp中的新Laravel應用會拋出404:nginx/1.4.6(Ubuntu)。我已經在下面發佈了我的nginx配置。這在AWS上的Ubuntu上運行,如果有幫助的話。Laravel在nginx上的子文件夾中

謝謝!

[更新!] - 現在我已經得到了根目錄和/ myapp Laravel應用程序文件夾中的所有內容,但資源似乎不起作用。例如http://example.com/myapp/public/css/app.css 404's,就像其他js和css文件一樣。不確定是什麼導致了這一點。我已確保公用文件夾具有完全權限,至少用於測試目的。還檢查了所有者/組,這與我的其他所有服務良好的文件相同,即ubuntu:ubuntu。

server { 

listen 80; 
server_name *.example.com; 
set $root_path '/usr/share/nginx/html/'; 
root $root_path; 

index index.php index.html index.htm; 

try_files $uri $uri/ @rewrite; 

location @rewrite { 
    rewrite ^/(.*)$ /index.php?_url=/$1; 
} 

location ~ \.php { 

    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index /index.php; 

    include /etc/nginx/fastcgi_params; 

    fastcgi_split_path_info  ^(.+\.php)(/.+)$; 
    fastcgi_param PATH_INFO  $fastcgi_path_info; 
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
} 

location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { 
    allow all; 
} 

rewrite ^/myapp/?(.*)$ /myapp/index.php?$1 last; 

location /myapp { 
    allow all; 
} 

location ~ /\.ht { 
    deny all; 
} 

} 
+0

我已經添加了上述編輯,以及一個新的配置文件。請在回覆前檢查更新!謝謝 :) – carbide20

回答

1

經過幾天的修補,我終於解決了它。它現在正確地加載主站點,孩子Laravel站點和所有資源。這是最後的配置,供參考。

server { 

    listen 80; 
    server_name *.example.com; 
    set $root_path '/usr/share/nginx/html/'; 
    root $root_path; 

    index index.php index.html index.htm; 

    try_files $uri $uri/ @rewrite; 

    location @rewrite { 
     rewrite ^/myapp/?(.*)$ /index.php?$1; 
    } 

    location ~ \.php { 

     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index /index.php; 

     include /etc/nginx/fastcgi_params; 

     fastcgi_split_path_info  ^(.+\.php)(/.+)$; 
     fastcgi_param PATH_INFO  $fastcgi_path_info; 
     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { 
     allow all; 
    } 

    location ~* ^/myapp/?(.+)/(css|img|js|flv|swf|download)/(.+)$ { 
     allow all; 
    } 

    location ~ \.css { 
     add_header Content-Type text/css; 
    } 

    location ~ \.js { 
     add_header Content-Type application/x-javascript; 
    } 

    location /myapp { 
     allow all; 
     rewrite ^/myapp/?(.*)$ /myapp/index.php?$1 last; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 

}