【问题标题】:Nginx returns 404 not found error when using domain nameNginx 使用域名时返回 404 not found 错误
【发布时间】:2014-08-01 22:01:55
【问题描述】:

我的 nginx 有问题,我的 ip 地址指向我的网站,但是当我将我的域指向该 ip 地址并尝试使用我的域名 (www.example.com) 访问我的网站时,nginx 返回一个404 错误。这是我的代码。

user www-data;
worker_processes 4;
worker_rlimit_nofile 100000;
pid /run/nginx.pid;

events {
use epoll;
worker_connections 1024;
multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 200;
reset_timedout_connection on;   
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

#gzip on;
gzip_disable "msie6";
gzip_min_length 256;
# gzip_vary on;
# gzip_proxied any;
 gzip_comp_level 3;
 gzip_buffers 16 32k;
# gzip_http_version 1.1;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

server{
listen 80;
   server_name vidzapp.com www.vidzapp.com;
    client_max_body_size 500m;

location /{
add_header 'Access-Control-Allow-Origin' "*";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Content-Type,accept,x-wsse,origin';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
    root /var/www;
    index index.php;
}


location ~ \.php$ {
root /var/www/; 
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

#   # 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;
include fastcgi_params;
}

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

}


}

【问题讨论】:

  • DNS 是否适用于该域?

标签: php nginx


【解决方案1】:

在位于@ /etc/nginx/sites-available/yourdomain.com 的虚拟主机文件中

查找并添加:DOMAIN.com www.DOMAIN.com *.DOMAIN.com;到服务器名称

 root /var/www/egaffar.com/datazone;
    index index.php index.html index.htm;
    # Make site accessible from http://localhost/
    server_name DOMAIN.com www.DOMAIN.com *.DOMAIN.com;

    location / {
        # First attempt to serve request as file, then

然后输入以下命令

nginx -t && 服务 nginx 重启

【讨论】:

    猜你喜欢
    • 2017-07-15
    • 1970-01-01
    • 2021-07-20
    • 2012-08-16
    • 2019-12-09
    • 2018-12-16
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    相关资源
    最近更新 更多