Yii v1.1 redirects to 404 nginx - nginx

My Yii 1.1 app redirects to site.com/login and gets error 404. Yii app hasn't any problems, it's an old app which I want to install on my server. The problem has to be with nginx configuration with mod_rewrite because pretty urls are not processed as they should.
Here i my default.conf:
server {
include snippets/phpmyadmin.conf;
listen 80 default_server;
charset UTF-8;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /home/fornex/tmp_7offers/public/;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name localhost;
client_max_body_size 30m;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 60;
fastcgi_send_timeout 60;
location /public {
root /home/fornex/tmp_7offers/public/;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
error_log /var/log/nginx/error-01.log;
index index.php index.html index.htm;
# proxy_pass http://localhost:8080;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection 'upgrade';
# proxy_set_header Host $host;
# proxy_cache_bypass $http_upgrade;
if (!-e $request_filename){
rewrite ^/(.*) /index.php?r=$1 last;
}
}
# 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)(/.+)$;
include snippets/fastcgi-php.conf;
include fastcgi_params;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
if ($request_uri ~ ^/(login)) {
error_page 404 =301 #redirect;
}
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
How can I enable mod_rewrite so pretty urls will processed as they should?

Related

How do I setup nginx for multiple web app with multiple subdomains in GCE

I am using GCE with LEMP stack. I have multiple subdomains and each subdomain has different root folder.
My setup is as below:
Production app
server {
listen 80;
listen [::]:80 ipv6only=on;
# SSL configuration
#
listen 443 ssl http2;
listen [::]:443 ipv6only=on ssl http2;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
ssl_certificate /etc/nginx/ssl/*.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/*.example.com.key;
server_name prod.example.com;
root /var/www/example/web;
client_max_body_size 10M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_read_timeout 3000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
# 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 ~ \.php$ {
return 404;
}
}
Staging app
server {
#listen 80;
listen [::]:80;
# SSL configuration
#
#listen 443 ssl http2;
listen [::]:443 ssl http2;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
ssl_certificate /etc/nginx/ssl/*.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/*.example.com.key;
server_name staging.example.com;
root /var/www/example-staging/web;
client_max_body_size 10M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_read_timeout 3000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
# 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 ~ \.php$ {
return 404;
}
}
They have the same config except for the server_name part. But, it seems like nginx is not able to tell apart the 2 different configuration.
No matter if I were to use prod.example.com or staging.example.com, both will only route to the prod root folder.
Is there anything wrong with my configurations that is causing this issue?
The issue is because of my "staging" app is listening to IPv6 only, I need to turn on IPv4 too, so now the different subdomains are routing correctly.

How do you point NGINX at standard PHP for multiple sites?

So I'm tasked with upgrading php that is used by NGINX in RHEL. I installed NGINX from the RHEL repo, but the instructions I followed to add PHP got it from the remi repo. I need to move over to PHP to meet the requirements of our Security team, but unsure how to configure it to do the same as I'm doing. I put this setup together with chicken wire and duct tape to support running 2 sites via NGINX. 1 is a rundeck site, the other is a wiki. With all the config, I'm confused as to how I would repeat the same without the remi install. Here's how I configure it:
Move nginx to port 8080 and separate off 2 sites for rundeck and wiki:
$vi /etc/nginx/nginx.conf (modify server block)
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
$vi /etc/nginx/conf.d/rundeck.conf
server {
listen 8080;
listen [::]:8080;
server_name mymachine.mydomain;
access_log /var/log/nginx/mymachine.mydomain.access.log;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location ^~ /wiki {
alias /var/www/wiki/html;
index index.php;
if (!-e $request_filename) { rewrite ^ /wiki/index.php last; }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
location / {
proxy_pass http://localhost:4440;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Change the rundeck config to point to port 8080:
$vi /etc/rundeck/rundeck-config.properties
grails.serverURL=http://mymachine.mydomain:8080
Change the rundeck framework properties file to point to the same server name:
$vi /etc/rundeck/framework.properties
framework.server.name = mymachine.mydomain
framework.server.hostname = mymachine.mydomain
framework.server.port = 4440
framework.server.url = http://mymachine.mydomain:4440
Any help? Thanks!
This is a server administration task and has nothing to do with PHP programming...
PHP-FPM runs on a separate server, or in your case, in a separate process on the same server. Requests are forwarded to this FPM server via port 9000 (the fastcgi_pass instruction).
The nginx webserver listens on port 8080, but you can basically use any port you'd want. Nevertheless, if you configure the same "server" to listen on multiple ports, it's still the same site (= same document root directory) - which is btw missing in your config...
But you can create a second "server" section and configure another site (=document root)...

PhpMyAdmin wrong display in Nginx using reverse proxy

I am running a NodeJS application in Nginx with a reverse proxy to port 3000
PhpMyAdmin is configured and apparently runs in /phpmyadmin
/etc/nginx/sites-available/default is configured like this:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost mywebsite.com www.mywebsite.com;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /phpmyadmin {
root /var/www/html/phpmyadmin/;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
I managed to make all work as I wanted, but PhpMyAdmin has a bad display:
Before setting the reverse proxy in that file, PhpMyAdmin ran perfect. I assume there is something I missed in default file. Any ideas? Thanks
To Ivan Shatsky's Response: #IvanShatsky
I tried substituting with your code, but it downloads a file (it does not read .php files) - So, I added few more lines:
location ^~ /phpmyadmin {
index index.php;
try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
The result is the same before.
When I check the resources of the network, this is what happens:
I have performed chmod 777 -R /var/www/html/phpmyadmin but no changes. Would I need to have https? - I am currently trying on http.
I wonder how it is running at all. Assuming your phpMyAdmin located in the /var/www/html/phpmyadmin directory, try this:
location /phpmyadmin {
index index.php;
try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
}

Cannot access Symfony app on Homestead VM

I have been trying to get a Symfony app to run on Homestead. Each time I try to load the site http://homestead.app my browser says "This site can’t be reached". I am not sure why this is happening. The process I followed was:
Create a Symfony application on my Linux mint host system:
mkdir ~/dev/sites/symfony
cd ~/dev/sites/symfony
symfony new my_project. This creates Symfony application in: "~/dev/sites/symfony/my_project"
composer require --dev laravel/homestead
php vendor/bin/homestead make
Edit Homestead config file vim Homestead.yaml
vagrant up
"Homestead.yaml" file contains:
ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
-
map: ~/dev/sites/symfony
to: /home/vagrant/Code
sites:
-
map: homestead.app
to: /home/vagrant/Code/my_project/web
type: symfony
databases:
- homestead
name: symfony
hostname: symfony
When I try to access the site through Chrome browser I get a 'The site can't be reached'. I checked the nginx config, but looks ok to me:
server {
listen 80;
listen 443 ssl http2;
server_name homestead.app;
root "/home/vagrant/Code/my_project/web";
index index.html index.htm index.php app_dev.php;
charset utf-8;
location / {
try_files $uri $uri/ /app_dev.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/homestead.app-ssl-error.log error;
sendfile off;
client_max_body_size 100m;
# DEV
location ~ ^/(app_dev|app_test|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;
internal;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/homestead.app.crt;
ssl_certificate_key /etc/nginx/ssl/homestead.app.key;
}
If I try to ping the site from host system ping homestead.app it is translating the address to 192.168.10.10 but fails to return a ping response. This indicated that the URL is being correctly mapped to the IP address.
I checked the '/etc/hosts' config for both host and guest systems. On the host system there is an entry for homestead.app which maps to 192.168.10.10. I noticed that in the guest system the hosts file only mapped homestead instead of 'homestead.app'. I updated the hosts file to include both. However, that didn't make any difference.

nginx configuration rafter replacing apache2

I was running apache2 on my laptop as a web server.Then i decided moving to nginx.
-Installed nginx - php (fastcgi - fpm) without removing apache
-configured the /etc/nginx/site-enabled/default with the next rules
root /var/www;
index index.html index.htm index.php;
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# 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 fastcgi_params;
}
Typenig localhost from the browser it responds with 403 forbidden
Typing 127.0.0.1:9000 This webpage is not available
12.0.0.1 forbidden
I see its a permissions issue but i run chmod 777 var/www
and apache2 when running display websites
So what's wrong with my configuration or what am i missing?
If the above is the only content of your default file, than I’m wondering why nginx is even starting. You have to create a server block:
server {
listen 80;
server_name _;
root /var/www;
index index.html index.htm index.php;
location /doc/ {
alias /usr/share/doc;
autoindex on;
allow 127.0.0.1;
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
}
Always check your configuration with nginx -t before (re-)starting.

Resources