我有一个域,我需要在不同的文件夹中托管许多symfony 3项目。例如:
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 :(得分:0)
我建议您创建一个伪apache设置,其中包含" sites-available"自动加载到你的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;
}
答案 1 :(得分: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;
...
}