nginx配置(任何网址转到“欢迎使用nginx”)

时间:2013-10-09 11:01:37

标签: ubuntu nginx

我刚刚在Ubuntu 13.04上安装了nginx 1.4.1,我遇到了这个问题:我去的任何网址都给了我"欢迎来到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;
}

}

2 个答案:

答案 0 :(得分:0)

如果您删除该部分该怎么办:

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

和位置/到

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

不要忘记重新启动nginx。

答案 1 :(得分:0)

您可能会在名为/etc/nginx/sites-enabled/的{​​{1}}内找到符号链接,将其删除。

问题可能是因为default文件被标记为default,而这个文件不是。{/ p>