0

我刚刚在 Ubuntu 13.04 上安装了 nginx 1.4.1,我遇到了这个问题:我去的任何 url 都会给我“欢迎使用 nginx”页面。

例子:

localhost
localhost/some/folder
localhost/some/folder/index.php

我的 nginx.conf:

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

events {
    worker_connections 768;
    # multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
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_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# 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
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

我的 conf.d/default.conf:

server {

listen 80;
server_name _;

root /home/web;

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ @handler;
}

location @handler {
    rewrite / /index.php;
}

location ~* .php/ {
    rewrite ^(.*.php)/ $1 last;
}

location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include     fastcgi_params;
}

}
4

2 回答 2

0

如果您删除零件怎么办:

location @handler {
    rewrite / /index.php;
}

和位置/到

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/;
}

不要忘记重新启动nginx。

于 2013-10-09T11:06:38.113 回答
0

你可能会在里面找到一个符号链接/etc/nginx/sites-enabled/default删除它。

问题可能是因为default文件被标记为default_server,而这个不是。

于 2013-10-09T11:06:50.600 回答