2017-06-06 75 views
1

我有一個域,我需要在不同文件夾中託管很多symfony 3項目。例如:在同一個域上託管多個Symfony項目

www.domain.com/project1 www.domain.com/project2 ...

我目前的nginx的conf是:

server { 
    server_name domain.fr www.domain.fr; 
    root /var/proximiteclient/www/web; 

    location/{ 
     # try to serve file directly, fallback to app.php 
     try_files $uri /app.php$is_args$args; 
    } 

    # PROD 
    location ~ ^/app\.php(/|$) { 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_split_path_info ^(.+\.php)(/.*)$; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 
     fastcgi_param DOCUMENT_ROOT $realpath_root; 
     # Prevents URIs that include the front controller. This will 404: 
     # http://domain.tld/app.php/some-path 
     # Remove the internal directive to allow URIs like this 
     #internal; 
    } 

    # return 404 for all other php files not matching the front controller 
    # this prevents access to other php files you don't want to be accessible. 
    location ~ \.php$ { 
     return 404; 
    } 

    error_log /var/log/nginx/domain_error.log; 
    access_log /var/log/nginx/domain_access.log; 

    listen 80; # managed by Certbot 

    listen 443 ssl; # managed by Certbot 
    ssl_certificate /etc/letsencrypt/live/domain.fr/fullchain.pem; # manag$ 
    ssl_certificate_key /etc/letsencrypt/live/domain.fr/privkey.pem; # man$ 
    ssl_session_cache shared:le_nginx_SSL:1m; # managed by Certbot 
    ssl_session_timeout 1440m; # managed by Certbot 
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # managed by Certbot 
    ssl_prefer_server_ciphers on; # managed by Certbot 

    ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE$ 



    #Redirect non-https traffic to https 
    if ($scheme != "https") { 
     return 301 https://$host$request_uri; 
    } # managed by Certbot 
} 

對不起,我不能放在文本模式下它不工作:(

Thansk非常感謝!

+0

你錯過了nginx的配置部分 – smarber

+0

加入!對不起,它拒絕我的conf :( –

+0

我已經添加了我的nginx conf! –

回答

0

我建議創建一個假的Apache設置,你必須「的網站,提供」自動加載到你的nginx配置中。

例如:

//nginx.conf 
include /etc/nginx/conf.d/*.conf; 
include /etc/nginx/sites-enabled/*; 

然後創建/etc/nginx/sites-enabled並創建一個「現場配置」爲各個域的。這將使他們乾淨地分開。

//etc/nginx/sites-enabled/dev.conf 
server { 
    listen 80; 
    ssl off; 
    server_name dev.example.com; 
    root /path/to/example/web; 
} 

server { 
    listen 443; 
    server_name dev.example.com; 
    return 301 http://$server_name$request_uri; 
} 

和良好的措施第二個站點..

//etc/nginx/sites-enabled/staging.conf 
server { 
    listen 80; 
    ssl off; 
    server_name staging.example.com; 
    root /path/to/example2/web; 
} 

server { 
    listen 443; 
    server_name staging.example.com; 
    return 301 http://$server_name$request_uri; 
} 
+0

當然,這不會爲一個單一的域設置工作,像OP要求,無需更改端口 – beterthanlife

+0

當然,它會,我的例子名稱誤導,我已經更新了它們,但是你可以很容易地爲每個'server_name'配置文件設置'{subdomain} .example.com'(我已經在幾個項目上做了很多很成功的工作)。 –

+0

同意,使用子域名是一件好事在這裏解決。 – beterthanlife

0

一個簡單的方法做,這是複製服務器塊,並指定一個不同的監聽端口和根路徑。

項目1個網址:http://www.domain.fr

server { 
    listen 80; 
    server_name domain.fr www.domain.fr; 
    root /var/project1/www/web; 
    ... 
} 

項目2網址:http://www.domain.fr:801

server { 
    listen 801; 
    server_name domain.fr www.domain.fr; 
    root /var/project2/www/web; 
    ... 
} 
相關問題