子域路由的行为与 Nginx 中的域不同
Subdomain routing behaves differently than domain in Nginx
我 运行 遇到一个问题,即指向域 example.com
returns 404 而子域 stage.example.com
指向相同资源的行为符合预期。我 运行 在 Ubuntu 上使用 Nginx 1.10.3。
这是此服务器的配置文件(/etc/nginx/sites-available/example.com
符号链接到 /etc/nginx/sites-enabled/example.com
)。
server {
# Root directory
root /home/username/example.com;
# Index
index index.php index.html index.htm index.nginx-debian.html;
# Server name(s)
server_name stage.example.com example.com www.example.com;
# Create access and error logs in /var/log/nginx
# access_log /var/log/nginx/example_com-access_log;
# error_log /var/log/nginx/example_com-error_log info;
# Generic location
location / {
# First attempt to serve request as file, the fall back
# to allow hashless routing
try_files $uri $uri/ /index.php;
}
location ~ \.json$ {
# Patching existing loading of JSON via post
# To allow POST on static pages
error_page 405 =200 $uri;
}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# route to headless use of wordpress
location /content/ {
try_files $uri $uri/ /content/index.php$is_args$args;
}
# route to api in headless wordpress
location ~ ^/api/ {
# if permalinks not enabled
rewrite ^/api/(.*?)$ /?rest_route=/ last;
}
# Deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
想法?
事实证明这是我的配置中没有正确处理 IPv6 的问题。像这样更新我的服务器配置解决了它:
server {
# Port(s)
listen 80 default_server;
listen [::]:80 ipv6only=on;
# Remainder of config identical to sample provided
}
这就是我找到解决方案的原因:https://www.digitalocean.com/community/questions/ipv6-connectivity-issues-with-nginx
我 运行 遇到一个问题,即指向域 example.com
returns 404 而子域 stage.example.com
指向相同资源的行为符合预期。我 运行 在 Ubuntu 上使用 Nginx 1.10.3。
这是此服务器的配置文件(/etc/nginx/sites-available/example.com
符号链接到 /etc/nginx/sites-enabled/example.com
)。
server {
# Root directory
root /home/username/example.com;
# Index
index index.php index.html index.htm index.nginx-debian.html;
# Server name(s)
server_name stage.example.com example.com www.example.com;
# Create access and error logs in /var/log/nginx
# access_log /var/log/nginx/example_com-access_log;
# error_log /var/log/nginx/example_com-error_log info;
# Generic location
location / {
# First attempt to serve request as file, the fall back
# to allow hashless routing
try_files $uri $uri/ /index.php;
}
location ~ \.json$ {
# Patching existing loading of JSON via post
# To allow POST on static pages
error_page 405 =200 $uri;
}
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# route to headless use of wordpress
location /content/ {
try_files $uri $uri/ /content/index.php$is_args$args;
}
# route to api in headless wordpress
location ~ ^/api/ {
# if permalinks not enabled
rewrite ^/api/(.*?)$ /?rest_route=/ last;
}
# Deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
想法?
事实证明这是我的配置中没有正确处理 IPv6 的问题。像这样更新我的服务器配置解决了它:
server {
# Port(s)
listen 80 default_server;
listen [::]:80 ipv6only=on;
# Remainder of config identical to sample provided
}
这就是我找到解决方案的原因:https://www.digitalocean.com/community/questions/ipv6-connectivity-issues-with-nginx