位置直接domain.com到多站点服务器上的www.domain.com

时间:2015-06-28 17:05:19

标签: linux web nginx url-rewriting location

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

我正试图强迫" www。"发生。我能够在Stackoverflow上找到以下解决方案。

"(\\w)\\1{5,}"

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

在一个网站上登录wordpress return 301 http://www.example.com$request_uri; 时,会将我转到www.site1.com/wp-admin。我认为这个问题与default_server或hostname问题有关。我是否需要将所有主机名添加到www.site0.com/wp-admin

这是我的主机文件

/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; #} }

请尽可能帮助,非常感谢。

1 个答案:

答案 0 :(得分:0)

我在这里找到了一份非常全面的指南: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到正确的域。