Azure Nginx from apache. htaccess.. php页面正在被下载,而不是呈现

56lgkhnf  于 2023-10-17  发布在  Nginx
关注(0)|答案(1)|浏览(100)

将网站从apache迁移到Azure应用服务- nginx和.htaccess重写让我感到不适。
下面是我的默认nginx文件。我可以让页面重定向,但它下载,而不是呈现的php。
但如果我加上:
default_type text/html;
页面将在没有PHP的情况下呈现。
我在这里做错了什么吗?或者我需要编辑nginx.conf吗?(我们甚至可以用App Service来编辑它吗?)

server {
    #proxy_cache cache;
    #proxy_cache_valid 200 1s;
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot;
    #index  index.php index.html index.htm;
    index  index.php;
    server_name  domain.com www.domain.com; 
    port_in_redirect off;

   location / {
        try_files $uri $uri/ /index.php?$args;
    }
    
    # nginx configuration by winginx.com

location /refer {
  rewrite ^/refer /refer.php break;
}

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /html/;
    }
    
    # Disable .git directory
    location ~ /\.git {
        deny all;
        access_log off;
        log_not_found off;
    }
    
    #default_type text/html;
    
    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    

    # Add locations of phpmyadmin here.
    #location ~* [^/]\.php(/|$) {
       # fastcgi_split_path_info ^(.+?\.[Pp][Hh][Pp])(|/.*)$;
       # fastcgi_pass 127.0.0.1:9000;
       # include fastcgi_params;
       # fastcgi_param HTTP_PROXY "";
       # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fastcgi_param PATH_INFO $fastcgi_path_info;
       # fastcgi_param QUERY_STRING $query_string;
       # fastcgi_intercept_errors on;
       # fastcgi_connect_timeout         300; 
       # fastcgi_send_timeout           3600; 
       # fastcgi_read_timeout           3600;
       # fastcgi_buffer_size 128k;
       # fastcgi_buffers 4 256k;
       # fastcgi_busy_buffers_size 256k;
       # fastcgi_temp_file_write_size 256k;
   # }
}
uz75evzq

uz75evzq1#

好吧,我想明白了,希望这个答案能在未来帮助到人们。把重写放在主位置/.就像下面。

location / {            
        index  index.php index.html index.htm hostingstart.html;
        try_files $uri $uri/ /index.php?$args; # Changed for Laravel
        rewrite  ^/refer$  /refer.php  last;
}

相关问题