I have an issue with my nginx server on Azure app service where I'm trying to remove the .php extension from my URLs but I can't seem to work out why my config isn't working.
I've followed the instructions exactly from here https://azureossd.github.io/2021/09/02/php-8-rewrite-rule with one exception of replacing index.php with $uri.php. I know the startup script (/home/site/startup.sh) works as it breaks my site when I restart the service.
My conf file is:
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /$uri.php?$args;
}
# 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;
}
# Add locations of phpmyadmin here.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
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;
}
}
Related
I been dealing with Azure App service to serve wordpress is using nginx,
here is the current nginx config that i am using but it gives me multiple " was loaded over HTTPS, but requested an insecure script" errors , any ideas how to solve this?
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot;
index index.php index.html index.htm;
server_name server.com;
port_in_redirect off;
access_log /home/data/access.log;
error_log /home/data/error.log;
# Custom to allow large file uploads
client_max_body_size 256M;
# 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;
}
# Add locations of phpmyadmin here.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
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;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$is_args$args =404;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
#The following parameter can be also included in fastcgi_params file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
i tried multiple configs from the page of nginx and wordpress. (none worked exactly many of the give me error 404 and too many redirects.
<?php
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
added this to wp config plus the part on nginx to make it work on azure app service
Im trying to configure nginx to serve laravel and yii project on same domain. My laravel project is working fine. Yii project also working but assets folder on yii project is giving err_aborted not found 404. All js css ... files are not found
server {
server_name mydomain.com;
index index.html index.php;
charset utf-8;
set $base_root /var/www;
# App 1 (main app)
location / {
root $base_root/telemele/public;
try_files $uri $uri/ /index.php?$query_string;
error_log /var/log/nginx/telemele.notice.log notice;
error_log /var/log/nginx/telemele.error.log error;
location ~* ^/index\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/telemele/public/index.php;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
}
# App 2
location ~* /mahabat {
alias $base_root/html/backend/web;
try_files $uri $uri/ /mahabat/index.php?$query_string;
error_log /var/log/nginx/mahabat.notice.log notice;
error_log /var/log/nginx/mahabat.error.log error;
location ~* ^/mahabat/index\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html/backend/web/index.php;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~* \.css|\.js|\.jpg|\.jpeg|\.png|\.gif|\.swf|\.svg|\.tiff|\.pdf$ {
try_files $uri =404;
}
location ~ ^/assets/.+\.php(/|$) {
deny all;
}
}
# Files
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# Error
access_log off;
rewrite_log on;
# Disable .htaccess access
location ~ /\.ht {
deny all;
}
}
What am i doing wrong? How to make nginx not to abort assets folder files? why it is giving not found?
There might be a missing .htacces file at the frontend/web directory. If you have the same problem, I recommend you to use this
My vagrant box doesn't parse PHP-files for Bolt CMS.
I'm a dev for years now, been working in Vagrant since about 5 years, and never had serious problems.
I wanted to give Bolt CMS a try, but when I fire my browser to the correct url (http://sallys.local:8000) it always wants to download the index-file (or any other file) instead of parsing it.
My vagrant-box is updated to the latest version 8.10, I use Nginx, but it seems as Nginx isn't called. I activated the acces-log and it shows no entries. For my other projects, same box, it does.
The Nginx-config for this one is:
server {
listen 80;
listen 443 ssl;
server_name sallys.local;
root "/home/vagrant/sallys/public";
index index.html index.htm index.php app.php;
charset utf-8;
location / {
try_files $uri $uri/ /app.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# access_log off;
access_log /var/log/nginx/sallys.local-ssl-acces.log;
error_log /var/log/nginx/sallys.local-ssl-error.log error;
sendfile off;
client_max_body_size 100m;
# DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/sallys.local.crt;
ssl_certificate_key /etc/nginx/ssl/sallys.local.key;
}
I have a similar setup for my other projects, and they all respond on port 8000. And parse PHP-files correctly. This seems to be a noob-problem. But I can't find the problem in here.
when I'm using the built-in server, it does work. So there must be a problem with Nginx.
Any one any idea?
Thanks
Tim
It looks like that is an Nginx site config for a Symfony 2/3 set-up (Symfony 4 is simpler FWIW), so it won't work "out of the box", so to speak.
My guess would be the location / {} as that is referencing app.php, and by default, a Bolt install will use index.php as the index file in the webroot.
There is a specific documentation page in Bolt's documentation that covers Nginx configuration specifically for a Bolt install, and I'd guess that'd be enough for your use case.
Thanks for pointing me out, Gawain. I tried your solution, but it didn't work. I removed the entries in my homestead file, reprovisioned vagrant, ..... and it works...
There is a new config generated:
server {
listen 80;
listen 443 ssl http2;
server_name sallys.local;
root "/home/vagrant/sallys/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/sallys.local-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/sallys.local.crt;
ssl_certificate_key /etc/nginx/ssl/sallys.local.key;
}
I am using Red Hat Enterprise server for hosting my phalcon based application. But after deployment the application is not working and showing "Please enable rewrite module on your web server to continue". I am using the below configuration in my default.conf file.
If any body has any idea plz help me to resolve the issue.
server {
listen 80;
server_name example.com www.example.com;
access_log /srv/www/example.com/log/access.log;
error_log /srv/www/example.com/log/error.log;
root /srv/www/example.com/public/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ #php_mvc;
}
location #php_mvc {
rewrite ^(.+)$ /index.php$1 last;
}
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_split_path_info ^(.+\.php)(/.*)?$;
set $script_filename $document_root$fastcgi_script_name;
if (!-e $script_filename) {
return 404;
}
fastcgi_pass fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param SCRIPT_FILENAME $script_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Can you please try to add following code in your nginx configuration and check it again.
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=$1;
}
This will work for you. (timeouts are high, you should change it for your app specs)
server {
listen 80 default_server;
server_name _;
client_max_body_size 128M;
location / {
root /var/www/public;
index index.php index.html index.htm;
try_files $uri $uri/ #rewrite;
fastcgi_connect_timeout 3000;
fastcgi_send_timeout 3000;
fastcgi_read_timeout 3000;
client_max_body_size 128M;
proxy_read_timeout 3000;
}
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=$uri&$args;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/public;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location ~ "\.(js|ico|gif|jpg|png|jpeg|xls|csv)$" {
root /var/www/public;
}
location ~* \.(jpg|jpeg|png|gif|ico)$ {
expires 365d;
log_not_found off;
access_log off;
}
}
I'm pretty new to using nginx and I'm having an issue where after requesting 500 pages from nginx running locally on my computer I start getting 504 Gateway Timeout error.
My nginx.conf file looks like this
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.php index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 5s;
include fastcgi_params;
}
}
server {
listen 80;
server_name local-testserver;
error_log logs/local-testserver.error.log;
access_log logs/local-testserver.access.log;
keepalive_timeout 1s;
location / {
root C:/Code/PHP/TestServer;
index index.php;
}
location ~ \.php$ {
root C:/Code/PHP/TestServer;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
}
And index.php in TestServer/ just contains
<?php
echo "hi";
?>
I'm testing this with the URLRequest class in AS3, but I actually tried manually sending 500 requests to see if that made a difference and in both cases the 501st request got a 504 error. Restarting the server allows me to make another 500 requests.
Any ideas on what might be happening or how to fix it?
Turns out this isn't an nginx issue at all but a FastCGI one. Setting PHP_FCGI_MAX_REQUESTS=0 as an environment variable before starting FastCGI should allow any number of requests.