I am currently trying to move our sites from apache and subdomains to nginx and the removal of subdomains.
Currently my folder structure has wordpress as the main directory and the shops living in a folder called shops.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/test.local;
index index.html index.htm index.php;
server_name test.local;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /proshop {
alias /var/www/test.local/shops;
try_files $uri $uri/ #nested;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location #nested {
rewrite /proshop/(.*)$ /shops/index.php?/$1 last;
}
location /shop {
alias /var/www/test.local/shops;
try_files $uri $uri/ #shop;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location #shop {
rewrite /shop/(.*)$ /shops/index.php?/$1 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
The problem i am facing is:
domain.com/proshop/ shows me my homepage allbeit with broken styling and js.....
however if i try
domain.com/proshop/admin
to get to the admin area i am hitting a 404?
Related
I have a react website which I am serving using NGINX. I wanted to create a blog for the same. So I tried to use wordpress in a sub-directory.
`
server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
location ^~ /blog {
client_max_body_size 10m;
if (!-f $request_filename) {
rewrite [^/]$ $uri/ permanent;
}
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^/wordpress(/.+\.php)(.*)$;
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
#ssl certificates here
}
`
After hours of reading docs, blogs and stack I got my homepage set up. However all my pages on the blog are returning 404. I am attaching my nginx config.
My directory structure is
/var/www/html/ : root folder for my react website
/var/www/html/blog : root folder for my wordpress ( no /wordpress subfolder present)
Add this lines
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/blog
}
how guys ,
i have server that have 3 location ,
i config my nginx like :
server {
listen 80;
listen [::]:80;
server_name www.zavie.co zavie.co 81.91.147.131;
location / {
root /home/zavie/zavieco/zavie;
index index.php coming-soon.html index.htm index.nginx-debian.html;
}
location /word {
index index.php index.html index.htm;
root /home/zavie/zavieco/word;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /phpmyadmin {
alias /home/zavie/zavieco/phpmyadmin;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
location /static/ {
root /home/zavie/zavieco/zavie360/zavie360;
}
location /zavie360 {
alias /home/zavie/zavieco/zavie360;
}
}
but when i open zavie.co/word this will not open wordpress , how i can config this ?
Unless you have installed WordPress under /home/zavie/zavieco/word/word, you have used the wrong value for the root directive. See this document for details.
Your location /word block does not have the ability to serve WordPress's static assets.
Use something like this:
location ^~ /word {
root /home/zavie/zavieco;
index index.php;
try_files $uri $uri/ /word/index.php;
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
See this document for details.
I tried to change the default URL of PhpMyAdmin so instead of accessing it through test.com/phpmyadmin I would do test.com/admin123
I tried this tutorial tutorial without success, I created a new symlink
Symlink
admin123 -> /usr/share/phpmyadmin/
Configuration
server {
index index.php index.html index.htm index.nginx-debian.html;
location /phpmyadmin {
root /usr/share/;
index index.php;
try_files $uri $uri/ =404;
location ~ ^/phpmyadmin/(doc|sql|setup)/ {
deny all;
}
location ~ /phpmyadmin/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Issues
I can still access normally /phpmyadmin and not /admin123. I restored Nginx and emptied my cache
I have a problem with nginx configuration. I wanna have Laravel app in subdirectory, exactly domain.com/alfa. At domain.com is another app. And now all Laravel routes gives 404 on nginx subdirectory. Could someone help find an error?
My paths:
/var/www/ <-- it's for domain.com
/var/www/alfa_path <-- it's for domain.com/alfa
It's my nginx configuration:
server
{
listen 80;
server_name domain.com;
root /var/www;
index index.php index.html index.htm;
location / {
}
location /alfa {
root /var/www/alfa_path/public;
index index.php index.html index.htm;
try_files $uri $uri/ /alfa_path/public/index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
I want to create a vhost for a php website in this folder:
/var/www/mydomain.com/home
and an alias for this folder for a wordpress blog:
/var/www/mydomain.com/public_html
I try this vhost:
server {
listen 80;
root /var/www/mydomain.com/home;
index index.php index.html index.htm;
charset UTF-8;
server_name mydomain.com;
access_log /var/log/nginx/mydomain.com.access.log;
error_log /var/log/nginx/mydomain.com.error.log debug;
location /blog {
alias /var/www/mydomain.com/public_html;
try_files $uri $uri/ /index.php?$args =404;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
With this configuration, my website work fine, the homepage of my blog is OK, static files are OK, the page like http://mydomain.com/blog/wp-login.php are OK, all the admin panel is OK :
http://mydomain.com/blog/wp-admin/
(wp-admin folder exist)
But the page in front of like
http://mydomain.com/blog/terms-and-conditions/
http://mydomain.com/blog/contact/
or all the page with / like blog/.../... always go to my /var/www/mydomain.com/home/index.php
What did I forget to do?