繁体   English   中英

nginx配置(任何URL都转到“欢迎使用nginx”)

[英]nginx configuration (any url goes to “Welcome to nginx”)

我刚刚在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;
}

}

如果您删除零件怎么办:

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

和位置/到

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

不要忘记重启nginx。

您可能会在/etc/nginx/sites-enabled/找到一个名为default的符号链接,将其删除。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM