Laravel is not receiving any $_GET variables from the URL query string. The $_GET and Input::all() are empty.
Example:
example.app/ex/login.php?country=US
The "country=US" never shows up in my $_GET variable
After much research and trying many different NGINX configurations, I can now only produce results when this example is used.
Example:
example.app/index.php/ex/login.php?country=US
The $_GET variable now shows the country name value pair.
What is the proper configuration to allow query strings within the URL?
My current sites-enabled configuration for my "example.app" is...
server {
listen 80;
server_name example.app;
root /home/vagrant/Code/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/registration.app-error.log error;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
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;
fastcgi_intercept_errors on;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
This appears correct, aside from being commented out.
location / {
#try_files $uri $uri/ /index.php?$query_string;
}
The bare bones one I use in testing is:
server {
listen 80 default_server;
root /var/www/project/public;
index index.php
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
$query_string and $args are functionally identical according to:
NGINX Docs
This is the sites-enabled NGINX server configuration that ended up working for me...
server {
listen 80;
server_name registration.app;
root /home/vagrant/Code/registration/public;
charset utf-8;
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/registration.app-error.log error;
error_page 404 /index.php;
sendfile off;
# Point index to the Laravel front controller.
index index.php;
location / {
try_files $uri $uri/ index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
#deny all;
}
}
For me it worked only by changing
try_files $uri $uri/ /index.php?$query_string; to
try_files $uri $uri/ /index.php?$args inside location / block on ubuntu (14.04) nginx
My NGINX congfiguration was something like this:-
From
location / {
try_files $uri $uri/ /index.php?is_args$args;
}
To
location / {
try_files $uri $uri/ /index.php?$args;
}
I just remove the is_args from try_files and working fine.
Related
I've got an nginx on my server and I am trying to get it to open the file '/config/www/pp1/index.php' for address https://example.com/pp1 and '/config/www/interpreter/index.html' for https://example.com/interpreter. Furthermore all things like https://example.com/interpreter/res/docs should fire up '/config/www/interpreter/res/docs.html'. I have made many attempts. Currently my default config file in /site-confs looks like this:
server {
listen 80;
listen 443 ssl http2;
server_name kni.mini.pw.edu.pl;
# Path for SSL config/key/certificate
ssl_certificate /config/keys/cert.crt;
ssl_certificate_key /config/keys/cert.key;
location / {
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;
proxy_pass http://kni_website;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
location /pp1 {
root /config/www;
index index.html index.htm index.php;
try_files $uri $uri/ index.php $uri/index.php /config/www/pp1/index.php index.php; #/index.php?$args =404;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# 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 /etc/nginx/fastcgi_params;
}
}
location /interpreter {
if ($request_uri ~* "([^/]*$)" ) {
set $last_path_component $1;
}
root /config/www;
index index.html index.htm index.php $last_path_component.html;
try_files /interpreter/res/$last_path_component.html $uri.html $uri.html $uri $uri/ /index.html index.php /$uri.html /index.php?$args =404;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# 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 /etc/nginx/fastcgi_params;
}
}
}
server {
listen 80 default_server;
listen 443 ssl;
root /config/www;
index index.html index.htm index.php;
server_name _;
ssl_certificate /config/keys/cert.crt;
ssl_certificate_key /config/keys/cert.key;
client_max_body_size 0;
location / {
try_files $uri $uri/ /index.html /index.php?$args =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# 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 /etc/nginx/fastcgi_params;
}
}
Quite frankly, I thought I knew what I was doing, however right now I am pretty certain that the location block location /interpreter is not being checked at all and the insides of location /pp1 are causing some crazy mumbo-jumbo.
Please help a newbie in need!
The main problem is that try_files will process its file elements within the current context, so you cannot handle your .html and .php URIs in the same statement. See this document for details.
One solution is to use a named location to split the try_files statement into two. First to test $uri, $uri.html and $uri/index.html, then a second to test $uri.php and $uri/index.php.
For example:
root /path/to/root;
location /foo {
try_files $uri $uri.html $uri/index.html #php;
location ~* ^(.*)\.php$ { return 301 $1; }
}
location #php {
try_files $uri.php $uri/index.php =404;
fastcgi_pass ...;
...
}
The location ~* ^(.*)\.php$ block is added to handle URIs that end with .php correctly. The simplest solution is to redirect them to a URI with the .php removed.
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
I have 2 links: myserver.org and myserver.org/support
I need first link follow to /var/www/myserver.org and second to /var/www/support
My config now:
first file & link
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
Second file & link:
server {
listen 80;
server_name 163.172.88.31/support;
charset utf-8;
root /var/www/support;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.163.172.88.31/support;
rewrite ^(.*) http://163.172.88.31/support$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}
First link works fine, second - no. I see '403 Forbidden'
What is not rigth?
Permissions for folders are the same, I think, they are right.
For both /var/www/myserver.org and /var/www/support you have to make two separate nginx config file with two different roots and server names .
besides , if you just want to show two links you can setup nginx for one and link the second one with just an internal link ( if they are in the same page)
Try like this:
include /etc/nginx/default.d/*.conf;
server {
listen 80 default_server;
server_name myserver.org;
charset utf-8;
root /var/www/myserver.org;
index index.php;
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
in /etc/nginx/default.d/ directory , create a .config file test.config:
location myserver.org {
proxy_pass /myserver.org;
}
location myserver.org/support {
proxy_pass /var/www/support;
}
This works:
groupmanager.org.conf
server {
listen 80 default_server;
server_name groupmanager.org;
charset utf-8;
root /var/www/groupmanager.org;
index index.php;
location /support/ {
alias /var/www/support/;
index index.php;
access_log /var/log/nginx/support_access.log;
error_log /var/log/nginx/support_error.log;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
}
}
access_log /var/log/nginx/groupmanager.org_access.log;
error_log /var/log/nginx/groupmanager.org_error.log;
include /etc/nginx/templates/php-fpm.conf;
}
server {
listen 80;
server_name www.groupmanager.org;
rewrite ^(.*) http://groupmanager.org$1 permanent;
}
php-fpm.conf
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
expires 168h;
}
location ~* \.(css|js)$ {
expires 180m;
}
I'm trying to install Symfony on my php5-fpm+nginx server on ubuntu.
When i'm entering to /web/app_dev.php it's displaying an error :
An error occurred while loading the web debug toolbar (404: Not
Found).
Do you want to open the profiler?
When i'm entering to profiler(/web/app_dev.php/_profiler/0db7ac) it tells:
No input file specified.
I know there is a problem with my server configuration file. Here it is:
server {
listen 80;
# listen [::]:80 ipv6only=on;
root /home/marker/Projects/stereoshoots/www;
access_log /home/marker/Projects/stereoshoots/logs/access.log;
server_name stereoshoots.local;
index index.php index.html index.htm;
location / {
autoindex on;
# try_files $uri $uri/ #rewrite;
try_files $uri $uri/ /index.php;
}
# location #rewrite {
# rewrite ^/(.*)$ /index.php?q=$1;
# }
location ~* \.(jpg|jpeg|gif|css|png|js|ico|xml|txt)$ {
access_log off;
expires 30d;
}
location = /favicon.ico {
return 204;
access_log off;
log_not_found off;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
What should i edit, to get symfony installed right?
Thanks!
I think the only thing left is to pass the uri to the index.php
try_files $uri $uri/ /index.php$request_uri
Do you really have index.php?
Try this:
index app_dev.php;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app_dev.php/$1;
}
location ~ \.php {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.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_param SERVER_PORT 80;
fastcgi_param SERVER_NAME stereoshoots.local;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index app_dev.php;
}
Notice that I changed location ~ \.php$ to location ~ \.php
I'm using Wordpress as root of my website and Invision Power Boards as forum.
http://localhost -> Wordpress
http://localhost/forum -> IPB
I have removed "index.php" from Wordpress URLs successfully with Nginx-rewrite however when I try to use SEO Friendly URLs on IPB, nginx simply returns to Wordpress' 404 page.
My configuration is like this:
#This removes "index.php" from Wordpress URLs
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
Then I follow this link to modify my nginx conf file in order to be able to use SEO friendly URLs of IPB: http://www.devcu.com/forums/topic/262-furl-friendly-urls-with-ipb-and-nginx/
#This part is to be able to use IPB SEO
location /forum/ {
index index.php;
try_files $uri $uri/ /forum/index.php?$uri&$args;
rewrite ^ /index.php? last;
}
When I click a link on my forum (for example: http://localhost/forum/index.php/forum/51-sport/) nginx simply redirects me to (http://localhost/forum/forum/51-sport/) which displays Wordpress 404 error page.
I have very little knowledge about regex so any help would be appreciated.
This is my whole conf file after modifications, little messy I accept that.
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home/user_name/public_html;
access_log /var/log/nginx/a/access.log;
error_log /var/log/nginx/a/error.log
server_name localhost;
server_tokens off;
location / {
try_files $uri $uri/ #wordpress;
}
location #wordpress {
fastcgi_pass php-fpm;
fastcgi_param SCRIPT_FILENAME /home/user_name/public_html$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME /index.php;
}
location /forum {
try_files $uri $uri/ try_files $uri $uri/ /forum/index.php?q=$uri;
}
location /forum/ {
try_files $uri $uri/ try_files $uri $uri/ /forum/index.php?q=$uri;
}
#location / {
#index index.php index.html index.htm;
#try_files $uri $uri/ /index.php?q=$uri&$args;
#}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/)(/.*)$;
}
# Add trailing slash to */wp-admin and */forum requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9001
#location ~ \.php$ {
# fastcgi_split_path_info ^(/)(/.*)$;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /home/user_name/public_html$fastcgi_script_name;
# fastcgi_param PATH_INFO $fastcgi_script_name;
# include /etc/nginx/fastcgi_params;
#REMOVE THIS
#fastcgi_read_timeout 60000;
#fastcgi_send_timeout 6000;
#}
}
Since the last post, I have played with IPB's SEO configurations and I managed to remove "index.php" from URLs. It doesn't effect the result of course. But it seems that location / decides what to do and therefore link is being considered as a Wordpress permalink.
EDIT - Solution
# Upstream to abstract backend connection(s) for php
upstream php {
# server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9001;
}
server {
## Your website name goes here.
server_name localhost;
## Your only path reference.
root /home/username/public_html;
## This should be in your http block and if it is, it's not needed here.
index index.php;
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
try_files $uri $uri/ /index.php;
}
location /forum {
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? break;
}
location ~ ^/forum/index.php {
if ($args != "") {
rewrite ^ http://www.google.com/ permanent;
}
try_files $uri $uri/ /forum/index.php;
rewrite ^ /forum/index.php? last;
}
location /forum/admin/ {
try_files $uri $uri/ /forum/admin/index.php;
rewrite ^ /forum/admin/index.php? last;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
I'm too using wordpress and ipb on nginx, now configuring, i added wordpress permalink to ipb config and turn on seo Rewrite URLs, Force Friendly URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
it worked for me