Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux (Nginx)非HTTP/Non-WWW到HTTPS/WWW导致下载PHP(无扩展名)文件_Linux_Url_Redirect_Nginx_Rewrite - Fatal编程技术网

Linux (Nginx)非HTTP/Non-WWW到HTTPS/WWW导致下载PHP(无扩展名)文件

Linux (Nginx)非HTTP/Non-WWW到HTTPS/WWW导致下载PHP(无扩展名)文件,linux,url,redirect,nginx,rewrite,Linux,Url,Redirect,Nginx,Rewrite,我已经浏览了好几个小时的各种线程(没有夸张),但是找不到一个解决方案组合,它允许我将非www和http转发到www和https,同时仍然能够在没有扩展名的情况下查看php文件。下面是我的nginx配置文件;感谢您的任何帮助 ## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unlea

我已经浏览了好几个小时的各种线程(没有夸张),但是找不到一个解决方案组合,它允许我将非www和http转发到www和https,同时仍然能够在没有扩展名的情况下查看php文件。下面是我的nginx配置文件;感谢您的任何帮助

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
    listen 80;
    server_name domain.com;
    rewrite ^(.*) http://www.domain.com$1 permanent;
}

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

    server_name www.domain.com;

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

    location / {
            try_files $uri $uri/ @extensionless-php;

            # 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$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location @extensionless-php {
            rewrite ^(.*)$ $1.php last;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #       deny all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#       listen 8000;
#       listen somename:8080;
#       server_name somename alias another.alias;
#       root html;
#       index index.html index.htm;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}


# HTTPS server

server {
    listen 443;
    server_name www.domain.com;

    root html;
    index index.html index.htm index.php;

    ssl on;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    ssl_session_timeout 5m;

    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;

    location / {
            try_files $uri $uri/ =404;
    }
}
提供了p.S.通用代码(即domain.com),以便其他人在需要时使用此解决方案


编辑:我已经解决了我自己的问题!请参阅下面我的解决方案。:)我找到了解决我自己问题的办法!希望这对一些人有用。基本上,NGINX配置文件中的修改是向前的
http://domain.com
http://www.domain.com
然后转发
http://www.domain.com
https://www.domain.com
,都不使用.php扩展名


也就是说,我可以在
https://www.domain.com/phpinfo.php
只需访问
domain.com/phpinfo
(或完整的URL,
https://www.domain.com/phpinfo
我已经找到了我自己问题的解决方案!希望这对一些人有用。基本上,NGINX配置文件中的修改是向前的
http://domain.com
http://www.domain.com
然后转发
http://www.domain.com
https://www.domain.com
,都不使用.php扩展名


也就是说,我可以在
https://www.domain.com/phpinfo.php
只需访问
domain.com/phpinfo
(或完整的URL,
https://www.domain.com/phpinfo
我已经找到了我自己问题的解决方案!希望这对一些人有用。基本上,NGINX配置文件中的修改是向前的
http://domain.com
http://www.domain.com
然后转发
http://www.domain.com
https://www.domain.com
,都不使用.php扩展名


也就是说,我可以在
https://www.domain.com/phpinfo.php
只需访问
domain.com/phpinfo
(或完整的URL,
https://www.domain.com/phpinfo
我已经找到了我自己问题的解决方案!希望这对一些人有用。基本上,NGINX配置文件中的修改是向前的
http://domain.com
http://www.domain.com
然后转发
http://www.domain.com
https://www.domain.com
,都不使用.php扩展名


也就是说,我可以在
https://www.domain.com/phpinfo.php
只需访问
domain.com/phpinfo
(或完整的URL,
https://www.domain.com/phpinfo
好的,这里对您的配置进行了一点简化,最终您想要转到https+www域,双重重定向是一种浪费。所以直接重定向到该域

server {
  # handles both www and non www to http
  listen 80;
  server_name www.example.com example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  # handles non www to https
  listen 443 ssl;
  # add ssl settings to avoid certificate error
  server_name example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  listen 443 ssl;
  server_name www.example.com;
  # ssl settings
  location / {
    try_files $uri $uri/ @extensionless;
  }
  location @extensionless {
    rewrite ^ $1.php last;
  }
  location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我相信这个小php块就足够了,如果它不起作用,你可以从你当前的配置中添加剩余的规则。

好吧,这里对你的配置进行了一点简化,最终你想要转到https+www域,双重重定向是一种浪费。所以直接重定向到那个

server {
  # handles both www and non www to http
  listen 80;
  server_name www.example.com example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  # handles non www to https
  listen 443 ssl;
  # add ssl settings to avoid certificate error
  server_name example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  listen 443 ssl;
  server_name www.example.com;
  # ssl settings
  location / {
    try_files $uri $uri/ @extensionless;
  }
  location @extensionless {
    rewrite ^ $1.php last;
  }
  location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我相信这个小php块就足够了,如果它不起作用,你可以从你当前的配置中添加剩余的规则。

好吧,这里对你的配置进行了一点简化,最终你想要转到https+www域,双重重定向是一种浪费。所以直接重定向到那个

server {
  # handles both www and non www to http
  listen 80;
  server_name www.example.com example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  # handles non www to https
  listen 443 ssl;
  # add ssl settings to avoid certificate error
  server_name example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  listen 443 ssl;
  server_name www.example.com;
  # ssl settings
  location / {
    try_files $uri $uri/ @extensionless;
  }
  location @extensionless {
    rewrite ^ $1.php last;
  }
  location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我相信这个小php块就足够了,如果它不起作用,你可以从你当前的配置中添加剩余的规则。

好吧,这里对你的配置进行了一点简化,最终你想要转到https+www域,双重重定向是一种浪费。所以直接重定向到那个

server {
  # handles both www and non www to http
  listen 80;
  server_name www.example.com example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  # handles non www to https
  listen 443 ssl;
  # add ssl settings to avoid certificate error
  server_name example.com;
  return 301 https://www.example.com$request_uri$is_args$query_string;
}
server {
  listen 443 ssl;
  server_name www.example.com;
  # ssl settings
  location / {
    try_files $uri $uri/ @extensionless;
  }
  location @extensionless {
    rewrite ^ $1.php last;
  }
  location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我相信这个小php块就足够了,如果它不起作用,您可以从当前配置中添加剩余的规则。

给我们一个下载任何php文件的示例url,即domain.com/info.php;它不是特定于文件的。目前,我正在将非www地址转发到www地址,并消除.php文件扩展名,但只要我尝试重写URL作为https而不是http,我得到了一个错误!@MohammadAbuShadygive给我们一个下载任何PHP文件的示例url,即domain.com/info.PHP;它不是特定于文件的。目前,我正在将非www地址转发到www地址,删除.PHP文件扩展名,但只要我尝试重写url作为https而不是http,我得到了一个错误!@MohammadAbuShadygive给我们一个下载任何PHP文件的示例url,即domain.com/info.PHP;它不是特定于文件的。目前,我正在将非www地址转发到www地址,删除.PHP文件扩展名,但只要我尝试重写url作为https而不是http,我得到了一个错误!@MohammadAbuShadygive给我们一个下载任何PHP文件的示例url,即domain.com/info.PHP;它不是特定于文件的。目前,我正在将非www地址转发到www地址,删除.PHP文件扩展名,但只要我尝试重写url如果是https而不是http,我得到了错误!@MohammadAbuShady