我是新手使用Nginx,嗯,新的使用任何不是cpanel的东西……当你包含www时,我在使用Nginx工作时遇到问题.在网址中.
www.mydomain.com > not work 404
mydomain.com > works
我不确定我是否在命名配置文件或Nginx的服务器配置上犯了错误.我有点匆匆学习,如果我在基本配置上犯了一些错误,我不会感到惊讶.我运行最新的Nginx& PHP-fpm,除了我的域名问题,它还可以.
我(尝试?)运行子域名,他们工作,但使用www.将导致404.我使用来自我的主.org服务器域的名称服务器等.
我将在下面发布所有相关内容,希望有人可以发现我正在制作/或制作的错误.
etc/hosts
# Do not remove the following line, or varIoUs programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
184.xxx.xxx.146 server.servername.org servername.org
named.conf中
...
view "localhost_resolver" {
/* This view sets up named to be a localhost resolver ( caching only nameserver ).
* If all you want is a caching-only nameserver, then you need only define this view:
*/
# match-clients { 127.0.0.0/24; };
# match-destinations { localhost; };
match-clients { any; };
match-destinations { any; };
recursion no;
zone "servername.org" {
type master;
file "/var/named/servername.org.db";
};
// optional - we act as the slave (secondary) for the delegated domain
zone "mydomain.com" IN {
type slave;
file "/var/named/mydomain.com.db";
masters {10.10.0.24;};
};
allow-notify { 184.xxx.xxx.146; };
};
mydomain.com.db
$TTL 86400
mydomain.com. IN SOA ns1.servername.org. server.servername.org. (
2002012013; Serial
1H ; Refresh (change 1H to 6H in 3 days or so)
1800 ; Retry (change to 1H in 3 days)
2W ; Expire
1D ); Minimum
mydomain.com. IN NS ns1.servername.org.
mydomain.com. IN NS ns2.servername.org.
ns1.servername.org. IN A 184.xxx.xxx.147
ns2.servername.org. IN A 184.xxx.xxx.148
mail.servername.org. IN A 184.xxx.xxx.146
mydomain.com. IN A 184.xxx.xxx.146
mydomain.com. IN MX 0 mail.servername.org.
@ A 184.xxx.xxx.146
www A 184.xxx.xxx.146
Nginx.conf使用include / etc / Nginx / sites-enabled / *;
和Nginx“mydomain.com”配置
server {
server_name www.mydomain.com;
rewrite ^(.*) http://mydomain.com$1 permanent;
}
server {
listen 80;
server_name mydomain.com www.mydomain.com;
# access_log /srv/www/mydomain.com/logs/access.log;
error_log /srv/www/mydomain.com/logs/error.log;
root /srv/www/mydomain.com/public_html;
set $noadmin 1;
location / {
try_files $uri $uri/ /index.PHP?$args;
index index.html index.htm index.PHP;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$$scheme://$host$uri/ permanent;
location ~ \.flv${
flv;
root /srv/www/mydomain.com/public_html;
}
location ~ \.mp4${
root /srv/www/mydomain.com/public_html;
mp4;
}
# use fastcgi for all PHP files
location ~ \.PHP${
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /srv/www/mydomain.com/public_html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
我可以访问子域名,所以我在这方面的可怕尝试似乎有点工作,我坚持为什么www.mydomain.com不会连接,而http://mydomain.com会.随着我的进展,我正在阅读/学习更多知识,在我了解变化的内容之前,我不想做出任何改变.我最终可能会破坏URL.
解决方法:
您将在Nginx.conf的前几行重写www.domain.com.如果我没错,重写和重定向是不同的事情.在第一个服务器块上试试这个;
server {
server_name www.mydomain.com;
return 301 http://mydomain.com$request_uri;
}
并改变
server_name mydomain.com www.mydomain.com
至
server_name mydomain.com
在第二个服务器块中.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。