0

Tried using the following code, but website only redirects back to default page not to a 404 error page

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /404.html;
                allow 192.168.1.127;
                allow 127.0.0.1;
                deny all;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/html;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       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;
        #}
}

Brand new to servers, all help is really appreciated. Also, I was following this guide: http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/

4

1 回答 1

0

首先我建议更改index规则,index.php一开始就提出,现在你的配置中没有任何 php 处理引擎,你在服务器上安装了 fastcgi 或 fpm 吗?

改变

index index.html index.htm index.php;

index index.php index.html;

在确定您拥有哪个 php 引擎后,我可以告诉您取消注释哪些行,现在没有 php 引擎 nginx 应该将 php 作为普通文件提供服务,在浏览器上打印它的数据或提示您下载 php 文件。

于 2013-06-21T15:24:34.250 回答