gpt4 book ai didi

linux - 在多站点服务器上将 domain.com 直接定位到 www.domain.com

转载 作者:太空宇宙 更新时间:2023-11-04 03:37:26 26 4
gpt4 key购买 nike

我的服务器正在 Debian Jessie 上运行 LEMP。

我正在尝试强制“www”。发生。我可以使用 Stackoverflow 上找到的以下解决方案来做到这一点。

return       301 http://www.example.com$request_uri;

但是,我正在从服务器运行多个网站,遇到的问题如下。

登录 WordPress 时 www.site1.com/wp-admin在一个网站上,它会将我引导至 www.site0.com/wp-admin 。我认为此问题与 default_server 或主机名问题有关。我是否需要将所有主机名添加到 /etc/hostname

这是我的主机文件

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

root /var/www/site0;

index index.php index.html index.htm;

server_name site0.com;
#return 301 http://www.site0.com$request_uri;
location / {
try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

server {
listen 80;
listen [::]:80;

# SSL configuration
#listen 443 ssl;
#listen [::]:443 ssl;

root /var/www/site1;

index index.php index.html index.htm;

server_name site1.com;
#return 301 http://www.site1.com$request_uri;
location / {
try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

我认为问题的一部分与以下方面有关: listen 80 default_server;
listen [::]:80 default_server;

如果可以的话请帮忙,我们将不胜感激。

最佳答案

我在这里找到了一个非常全面的指南:https://www.digitalocean.com/community/tutorials/how-to-configure-single-and-multiple-wordpress-site-settings-with-nginx

您可能会发现相关的部分是:

# Rewrite rules for WordPress Multi-site.
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

似乎正在重写 WordPress 请求,特别是 /wp-admin 到正确的域。

关于linux - 在多站点服务器上将 domain.com 直接定位到 www.domain.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31102448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com