2013-10-09 57 views
0

我剛剛在Ubuntu 13.04上安裝了nginx 1.4.1,我遇到了這個問題:我去的任何網址都給了我「Welcome to nginx」頁面。nginx配置(任何網址轉到「歡迎使用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; 
} 

} 

回答

0

如果您取下部分:

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

和位置/到

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

不要忘記重啓nginx的。

+0

這不起作用 – Caballero

+0

那麼......你有哪些文件?假設你的文件在/ home/web中。確保它們可以被用戶nginx運行。 –

0

您可能會在/etc/nginx/sites-enabled/內部找到一個名爲default的符號鏈接,將其刪除。

這個問題可能是因爲default文件被標記爲default_server而這個不是。

+0

試過,沒有改變什麼 – Caballero

+0

好,然後添加'default_server'到這個 –