我在ubuntu液滴中添加了2个域。 A.com 和 b.com 。两者都将记录重定向到IP。
我还为两个域创建虚拟主机。喜欢
server {
listen 80;
listen [::]:80;
root /var/www/html/b.com;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
server_name b.com www.b.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
,但是b.com并未将其重定向到Desire文件夹。当我从URL访问域时。它的重定向到主IP文件夹,例如/var/www/html ,而不是>/var/www/html/b.com
我的默认虚拟主机
server {
listen 80;
listen [::]:80;
root /var/www/html/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
我遵循以下指令,但仍然不起作用:https://www.digitalocean.com/community/tutorials/how-to-to-set-up-nginx-server-nginx-server-blocks-virtual-hosts-nosts-on-ubuntu-16--04
server_name _;
是一台接管服务器,如果它首先出现在您的配置中,则将首先提供。您可以在此处阅读有关此信息的更多信息:http://nginx.org/en/docs/http/server_names.html
如果将其更改为
server_name a.com www.a.com;
它应该对您有用。我建议您阅读文档的这一部分:http://nginx.org/en/docs/http/request_processing.html
完整配置:
server {
listen 80;
server_name b.com www.b.com;
root /var/www/html/b.com/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
location / {
try_files $uri /index.php?$args;
}
location ~ .php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}