【发布时间】:2019-11-13 09:28:26
【问题描述】:
我正在使用 CentOs 6.8
在开发模式下使用 CloudFlare DNS
Nginx 显示欢迎页面,从
/usr/share/nginx/html
但不是来自:
/home/nginx/domains/XYZDomain.com/public/
在目录中:
/etc/nginx/conf.d
2 个配置文件:
default.conf
virtual.conf
default.conf 文件输出
# Main Local
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
#
location ~ \.php$ {
include fastcgi_params;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}
virtual.conf 文件输出:
server {
listen 80;
#server_name www.XYZDomain.com;
# Now Changed to below withouth wwww.
server_name XYZDomain.com;
rewrite ^/(.*) http://XYZDomain.com/$1 permanent;
location / {
root /home/nginx/domains/XYZDomain.com/public/;
index index.html;
}
}
/etc/nginx/nginx.conf 输出中的 nginx.conf 文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
#default_type application/octet-stream;
#changed to text/html
default_type text/html;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
所有具有权限的目录。
ls -la /home/nginx/domains/XYZDomain.com
drwxr-s--- 6 root root 4096 Jul 1 12:54 .
drwxr-xr-x 3 root root 4096 Jul 2 14:44 ..
drwxr-s--- 2 root root 4096 Jun 30 15:58 backup
drwxr-s--- 2 root root 4096 Jun 30 15:58 log
drwxr-s--- 2 root root 4096 Jun 30 15:58 private
drwxr-sr-x 2 root root 4096 Jul 2 15:01 public
我试过修改default.php和virtual.conf文件
任何人都可以帮助我这有什么问题吗?我真的很困惑,为此浪费了一整天。
【问题讨论】:
-
您是否缺少“XYZDomain.com”的
server?您似乎将“www.XYZDomain.com”重定向到“XYZDomain.com”,如果指向该主机将由default.conf中的server块处理。 -
@RichardSmith 我在
virtual.conf中将server_name www.XYZDomain.com更改为server_name XYZDomain.com。尽管如此,它仍然在做同样的事情。对不起,我是新手,我会尽我所能。 -
将
default_type application/octet-stream;更改为default_type text/html;仍然相同.. -
一个好的调试步骤是禁用
default.conf并再次点击它。查看您是否获得了预期的页面或其他内容,这将让您知道它是否至少在拾取您的virtual.conf文件。我相信你已经知道这一点,但既然你提到你是新手,请务必在进行配置更改后重新加载 nginx。 -
@patrick3853 stackoverflow.com/questions/19285355/… 这帮助我将 nginx.conf 中的用户更改为 root 虽然,我想这可能是有害的?
标签: nginx server vps centos6.8