2017-06-06 65 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; 
    ... 
} 
相关问题