Hello guys I have a VPS with Ubuntu 20.04.
I have code-server installed and it works properly.
I also have Phpmy admin installed and mariadb, but when i go to my.ip.adress/phpmyadmin i get an 404 error.
I think the problems is that code-server tries to resolve the path or something like this.
My configuration looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name 178.254.34.3;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
root /usr/share/phpmyadmin;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
index index.php index.html index.htm index.nginx-debian.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Does someone can help me to solve this problem ?
I tried almost everything i could find on the web and it didnt solved the problem.
So I found the problem and it was very obvius at the end. When i first installed code-server i had to create a specifig configuration. so first of all my server was never using the default configuration i posted here. I changed a few things and now it works. At least I am able to see the login page and the info.php file i created. Thanks for your help.
Related
I'm new at nginx and i'm trying to deploy a react application but things is not working very well.
I have my dist folder with my static files (index.html, css and js) in /home/ec2-user/difo/digital-input-for-operators-react/dist.
My default page of nginx is working well in port 80, but when i try to reach the port 3000 (which is the number that i put in the listen directive) i have 404 error page.
I tried difo.ucnet.g-ushin.com:3000, i got this:
server {
listen 3000;
server_name difo.ucnet.g-ushin.com localhost;
access_log /etc/nginx/logs/difo-react.log;
root /home/ec2-user/difo/digital-interfaces-for-operators-react/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
Then i tried to create a simple html page to make some tests. I moved this new index.html to an new folder called page in the root folder of nginx and in my conf/server block i tried this:
server {
listen 3000;
server_name difo.ucnet.g-ushin.com localhost;
access_log /etc/nginx/logs/difo-react.log;
root page;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
And also dont work.
Can someone help me try to understand how can i setup the server block in conf.d?
I moved the dist folder to the same folder that nginx is getting the default index.html and worked. I guess is a permission problem.
I'm trying to set up an nginx server to serve a React app at the address http://mydomain/memorygame
Currently I have the following nginx routing config:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/mydomain.com;
index index.html;
server_name mydomain.com www.mydomain.com;
location /memorygame {
root /var/www/mydomain.com/memorygame;
try_files $uri /$uri $uri/ /index.html $uri/index.html =404;
location ~* \.(css|js)$ {
try_files $uri /$uri =404;
}
}
The css files are stored under /var/www/mydomain.com/memorygame, in the index.html the link is /static/css/main.d5dd0bd5.css.
The index.html load fine, but the css requests aren't routed to where I want them. If I take out "/index.html" from try_files, the css loads, but index.html doesn't. How can I make them both work at the same time?
(My guess is that part of the problem is that css request issued goes to mydomain.com/static/css/style.css instead of mydomain.com/memorygame/static/css/style.css, but I might be wrong. If I'm correct, is there a way to auto-prepend the /static/css/style.css to be relative to the mydomain.com/memorygame folder?)
Thanks in advance!
I figured it out myself. Deleting everything out of the location /memorygame block did the trick. Nginx does what I was trying to achieve by default.
I just installed nginx and php fastcgi about an hour ago, and after reading examples of a quick starting configuration, and the nginx documentation etc, I just cant get it to work.
No matter what I change or try, I always only get the "Welcome to Nginx!" screen on "localhost/..." - I cant even call a simple index.html
My config:
(the stuff in the comments is what I tried out)
// default nginx stuff (unchanged)
server {
#listen 80 default_server;
#listen 80 default;
listen 80;
#server_name localhost;
#server_name _;
#access_log /var/log/nginx/board.access_log;
#error_log /var/log/nginx/board.error_log;
#root /var/www/board;
#root /var/www/board/public/;
root /var/www/board/public;
#index index.html;
index index.html index.htm index.php;
}
If I understand it right, this should be the easiest setup, right? just define listen 80; and index index.html; but I just cant get it to work
The file /var/www/board/public/index.html exists and has content
Before I waste 2 more hours trying out something, can someone of you give it a quick watch and tell me what I'm doing wrong? Thanks.
Fundamentally you hadn't declare location which is what nginx uses to bind URL with resources.
server {
listen 80;
server_name localhost;
access_log logs/localhost.access.log main;
location / {
root /var/www/board/public;
index index.html index.htm index.php;
}
}
I have a concrete5 site that works 'out of the box' in apache server. However I am having a lot of trouble running it in nginx.
The following is the nginx configuration i am using:
server {
root /home/test/public;
index index.php;
access_log /home/test/logs/access.log;
error_log /home/test/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ index.php;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# pass the PHP scripts to FastCGI server listening on unix socket
#
location ~ \.php($|/) {
fastcgi_pass unix:/tmp/phpfpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I am able to get the homepage but am having problem with the inner pages. The inner pages display an "Access denied". Possibly the rewrite is not working, in effect I think its querying and trying to execute php files directly instead of going through the concrete dispatcher.
I am totally lost here.
Thankyou for your help, in advance.
Changed the configurations to:
server {
root /home/test/public;
index index.php;
access_log /home/test/logs/access.log;
error_log /home/test/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php/$request_uri;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# pass the PHP scripts to FastCGI server listening on unix socket
#
location ~ \.php($|/) {
set $script $uri;
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_intercept_errors on;
fastcgi_pass unix:/tmp/phpfpm.sock;
}
location ~ /\.ht {
deny all;
}
}
And it works thanks to hangover and the link he provided in serverfault.
I am still not clear what I did wrong, maybe an nginx expert can help me understand.
I'm googling a lot and found several workarounds, but you have to define every single directory.
On Apache: example.com/hi -> example.com/hi/
On nginx: example.com/hi -> Firefox can't establish a connection to the server at example.com:8888
where 8888 is what Apache is listening on (nginx's :80 -> localhost:8888)
Any ideas how to fix this and have it just forward normally like folder?
I had a similar problem with varnish and nginx (varnish on port 80 proxying to nginx listening on 8080) and needed to add "port_in_redirect off;" ... server_name_in_redirect needed to stay on so nginx knew which host it was handling.
The following should do the trick, but it needs more thought/work, because only a single location block will get used at a time:
location ~ ^(.*[^/])$ {
if (-d $document_root/$1) {
rewrite ^(.*)$ $1/ permanent;
}
}
(not tested)
You can set "server_name_in_redirect off" on your server section
server{
listen 80 default;
server_name localhost;
server_name_in_redirect off;
...
...
}
That will do the trick ;-)
HTH.
Edit: Just format.
This is the magic that works best for me:
try_files $uri $uri/ #redirect;
location #redirect {
if ($uri !~ '/$') {
return 301 $uri/$is_args$args;
}
}
The 'if' statement here is safe per: http://wiki.nginx.org/IfIsEvil