Nginx Windows URL Rewrite Error - php

I installed a portable nginx and php5.3 on windows 7 64bit and I created a sample site needs a url rewrite to run this is the error I always get after my configuration.
2014/11/30 22:56:12 [crit] 2356#3384: *1 GetFileAttributesEx() "D:/nginx/nginx/nginx-1.2.3/html/main.site.dev/index.php/" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 192.168.1.109, server: main.site.web, request: "GET / HTTP/1.1", host: "main.site.web"
here is my current windows nginx server block config:
server {
listen 80;
server_name main.site.web;
root D:/nginx/nginx/nginx-1.2.3/html/main.site.dev;
location / {
try_files $uri index.php$uri$args /index.php$uri$args /index.php;
}
location ~ \.php\/(.+)$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
break;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
location = /php-fpm-ping {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
Notice the "/" at the end of "index.php". What is wrong with the configuration.
Also note that the directory on this window is fully controlled (read & write).
Any suggestion or comments are appreciated. Thank you in advance...

Related

Running Wordpress/NGINX from different path

Im learning NGINX, so any help is really appreciated.
I have the frontend of a website running as the root of mysite.com, and now I want to run wordpress from mysite.com/blog.
My file structure is:
/srv/mysite/frontend
/srv/mysite/wordpress
this is the error i've been getting from the nginx logs
2020/03/29 00:09:03 [error] 23049#23049: *39 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: XXXXXXX, server: www.mysite.com, request: "GET /api HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "mysite.com"
and this is my nginx config file so far
listen 80 default_server;
server_name www.mysite.com mysite.com;
charset utf-8;
location ^~ /blog {
root /srv/mysite/wordpress;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location / {
root /srv/mysite/frontend/dist;
try_files $uri /index.html;
}
}
This error message shows either the wrong path of the sock file or the permissions. Make sure the php sock file exists in the path /run/php/php7.2-fpm.sock and change the permissions of the file.
For Debian
chown -R wwww-data:www-data /run/php/php7.2-fpm.sock
For Rhel
chown -R nginx:nginx /run/php/php7.2-fpm.sock
Also, you can try this config.
location /blog {
root /srv/mysite/wordpress;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

PHP with gitlab bundled nginx not working

I've setup gitlab using the omnibus package on CentOS 7. I'd like to use the gitlab server to host additional websites. I've enabled custom nginx conf by adding the below code to /etc/gitlab/gitlab.rb
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"
I've also created conf files in /etc/nginc/conf.d. Static HTML files are working but when i try to run php scripts, I'm getting a File not found - 404 error.
Following is the nginx conf for php :
server{
listen 80;
server_name example.com;
root /var/www/vhosts/example;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/gitlab/embedded/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /opt/gitlab/embedded/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The following is the error log:
FastCGI sent in stderr: "Primary script unknown" while reading response from upstream, client x.x.x.x, server: example.com, request: "GET / HTTP/1.1", upsteam: "fastcgi://127.0.0.1:9000", host: "example.com"
Maybe your problem comes from your "location ~ .php$" config.
You already fix the first problem with gitlab omnibus by included the right fatscgi_params instead of the default. Now it seems to comes from the location config.
Try the following code for your configuration :
location ~ \.php$ {
#in your case maybe : /opt/gitlab/embedded/html
root [YOUR APP DIRECTORY];
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include /opt/gitlab/embedded/conf/fastcgi_params;
}
This fix works for me on a Debian 8 server.
Hope it could help.

Can’t password protect wp-login.php, nothing happened

I have Ubuntu 14.04, Nginx 1.6.2, PHP 5.5.23-1+deb.sury.org~trusty+2 and fastcgi VPS. I setup my WordPress sites with Easy Engine. I want to enable password protect all my WordPress sites "wp-login.php" as well as "wp-admin" area. To test this process I have added following code to site enabled directory (/etc/nginx/sites-enabled) site file (mysite.com).
location ^~ /wp-login.php {
auth_basic "Restricted Area:WordPress";
auth_basic_user_file /var/www/.htpasswd;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
My VPS php-FPM use use fastcgi_pass 127.0.0.1:9000; so I used it in above code.
Then I created .htpasswd file and uploaded to /var/www directory and set the permission to rw-r-----.
Then I restarted php and nginx with service php5-fpm reload && service nginx reload command. Now when I try access /wp-login.php nothing changed. It's just like the regular login page and not promote any password popup window. I can't see any error or warning.
Due to the above /wp-login.php file password protection not working, I added password protection to the /wp-admin/ folder, then it working. This is my new nginx site enabled config file.
server {
server_name mysite.com www.mysite.com;
access_log /var/log/nginx/mysite.com.access.log rt_cache;
error_log /var/log/nginx/mysite.com.error.log;
root /var/www/mysite.com/htdocs;
index index.php index.html index.htm;
include common/w3tc.conf;
include common/wpcommon.conf;
include common/locations.conf;
include common/pagespeed.conf;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
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;
}
location /wp-admin/admin-ajax.php {
allow all;
}
location /wp-admin {
location ~ /wp-admin/admin-ajax.php$ {
# Php handler
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}
location ~* /wp-admin/.*\.php$ {
auth_basic "Restricted Area:WordPress";
auth_basic_user_file /var/www/.htpasswd;
# Php handler
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}
}
}
Could someone please tell me how do I fix this issue?
The problem is /wp-login.php already declared inside wpcommon.conf
So, copy /etc/nginx/common/wpcommon.conf to /var/www/example.com/my-wpcommon.conf
Edit this block
location = /wp-login.php {
limit_req zone=one burst=1 nodelay;
include fastcgi_params;
fastcgi_pass php;
}
into
location = /wp-login.php {
limit_req zone=one burst=1 nodelay;
include fastcgi_params;
fastcgi_pass php;
satisfy any;
allow 127.0.0.1;
deny all;
auth_basic "Authorization Required";
auth_basic_user_file /var/www/.htpasswd;
}
then edit your site nginx configuration at /etc/nginx/sites-available/example.com, replace
include common/wpcommon.conf;
into
include /var/www/example.com/my-wpcommon.conf;
Restart nginx.
However, please check /etc/nginx/common/wpcommon.conf every time you update your EasyEngine in case of new configuration so your my-wpcommon.conf would still be updated.
Since you are using fastcgi, you need to include your fastcgi processing in the location block for the PHP file.
location ^~ /wp-login\.php$ {
auth_basic "Restricted Area:WordPress";
auth_basic_user_file /var/www/.htpasswd;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}

nginx error "rewrite or internal redirection cycle" on CakePHP Project

I have created a default CakePHP 2.4 project and created the Nginx configuration as follows but I am getting these errors from Nginx error log. What I have done wrong?
My environment:
Debian (wheezy)
nginx/1.2.1
project directory /var/www/backhaus
The error is:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal redirection cycle while processing "/backhaus", client: xxx.x.x.xx, server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
Here is my config from ../sites-available/default:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Your error is this:
$ 2014/06/14 09:39:22 [error] 5952#0: *1 rewrite or internal
redirection cycle while processing "/backhaus", client: xxx.x.x.xx,
server: azazel, request: "GET /backhaus HTTP/1.1", host: "azazel"
And the error clearly states:
…redirection cycle while processing "/backhaus"…
So now, let’s look at your posted Nginx config:
location /backhaus {
root /var/www/backhaus/app/webroot/;
index index.php;
rewrite ^/* /backhaus;
location ~ ^/(.+\.php)$ {
try_files $uri $uri/ =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
It seems like the issue is your location is /backhaus but then you are redirecting any traffic going to /backhaus to /backhaus via this line:
rewrite ^/* /backhaus;
So I would recommend just removing that rewrite line.

Can't combine alias with fastcgi_cache in Nginx

This works:
location ~ ^/special/(.+\.php)$ {
alias /var/special/$1;
try_files "" =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; # php-fpm socket
}
But this doesn't:
location ~ ^/special/(.+\.php)$ {
alias /var/special/$1;
try_files "" =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; # php-fpm socket
fastcgi_cache mycache;
}
If I try to go to the URL "/special/index.php" I get a "File not found." text in the browser, which I assume comes from php-fpm or PHP. And I get this error in the Nginx log:
FastCGI sent in stderr: "Primary script unknown", client: 202.179.27.65, server: myserver.org, request: "GET /special/index.php HTTP/1.1", host: "myserver.org"
Any idea why adding fastcgi_cache breaks this?
Note that fastcgi_cache works fine when I use a location that doesn't use an alias.
After a few days (!) of fiddling with it, this variation seems to work:
location ~ ^/special(/.+\.php)$ {
root /var/special;
try_files "" =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; # php-fpm socket
fastcgi_cache mycache;
fastcgi_param SCRIPT_FILENAME $document_root$1;
fastcgi_param SCRIPT_NAME $1;
}
What seemed to make the difference is 1) using "root", which seems to be needed by the fastcgi_cache, and 2) explicitly setting SCRIPT_FILENAME and SCRIPT_NAME, because otherwise the "root" wouldn't work (even without fastcgi_cache).

Categories