I have tried many things but I cant seem to make it work.
I am running CentOS6 64-bit. Latest NGINX version installed.
I cannot seem to go to http://domain.com/phpmyadmin aftet switching from Apache.
Please help, thanks.
Here is my Default.conf:
# The default server
#
server {
listen 80 default_server;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/html;
index login.php index.php;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
EDIT:
FIXED
Moved the PHPMYADMIN folder from /usr/share to my web directory.
And now you broke the package. For prosperity:
location /phpmyadmin {
root /usr/share;
}
Related
I'm trying to set up a docker container using Nginx default image and add a simple health route to it as proposed here.
My config is as follows, and I am placing it under /etc/nginx/conf.d/bacon.conf.
# bacon.conf
server {
listen 80;
location /health {
access_log off;
add_header 'Content-Type' 'application/json';
return 200 '{"status":"Healthy"}';
}
}
When I try to access this /health route I end up getting a 404.
I've noticed there is already a default conf file on etc/nginx/conf.d/ called default.conf.
# default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
If I remove this default file from my container or if I merge both of them on a single file, my /health route starts working just fine.
I also checked nginx.conf under /etc/nginx which has this line:
#nginx.conf
...
include /etc/nginx/conf.d/*.conf;
...
From what I understand this should make NGinx mix all files ending in .conf into a single configuration file, shouldn't it?
For the sake of simplicity I would like to keep both files, how can I achieve this?
I'm trying to redirect all the requests hitting my page to an image. Inside my default.conf I have this:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ /usr/share/nginx/html/10343632.jpeg;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
the jpeg file is the image and it's located in /usr/share/nginx/html and I have removed all the other files from that directory. Every time I hit the page it gives a :
rewrite or internal redirection cycle while internally redirecting to "/usr/share/nginx/html/10343632.jpeg
I've also tried :
try_files $uri /usr/share/nginx/html/10343632.jpeg;
and
try_files $uri /10343632.jpeg;
and got the same error. The point of this is to serve an image no matter what the user requested.
The location section must account for root such that :
location / {
root /usr/share/nginx/html/;
try_files $uri /10343632.jpeg;
}
and it'll work!
When I am accesing page at http://myIP I am seeing files in folder
var/www/html
instead of
var/www/html/src/public
I have set up following setting in /etc/nginx/sites-available/default:
root /var/www/html/src/public;
index index.html index.htm;
and also restarted nginx.
What could be wrong? Thank you in advance.
You need to define your document root in:
/etc/nginx/nginx.conf
Or define it in your virtual host config file in:
/etc/nginx/conf.d/default.conf
Here is an example default.conf file setup:
server {
listen 80;
listen 443 ssl;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
server_name adamsawesomewebsite.tk;
root /var/www/vhosts/adamsawesomewebsite.tk/httpdocs;
index index.php index.html;
#charset koi8-r;
#access_log /var/log/nginx/access.log main;
# redirect server error pages to the static page /40x.html
#
#error_page 404 /404.html;
#location = /40x.html {
#}
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
I have a problem with both RoundCube and phpMyAdmin. I have varnish running on port 80 and nginx running on 8080.
When I go to phpmyadmin.domain and log in, it will redirect me to phpmyadmin.domain:8080.
When I go to webmail.domain and try to log in, it keeps reloading the login page unless you go to webmail.domain:8080 and log in, then it will work.
I have tried
port_in_redirect off;
but it still seems to need 8080.
Nginx config for phpmyadmin:
server {
listen 8080;
server_name phpmyadmin.domain.name;
port_in_redirect off;
access_log /var/log/nginx/phpmyadmin.access.log;
error_log /var/log/nginx/phpmyadmin.error.log;
root /var/www/phpmyadmin.domain.name/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Nginx config for webmail:
server {
listen 8080;
server_name webmail.domain.name;
root /usr/share/roundcubemail;
port_in_redirect off;
# Logs
access_log /var/log/roundcubemail/access.log;
error_log /var/log/roundcubemail/error.log;
# Default location settings
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
# Redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
#error_page 404 /404.html;
# Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead)
location ~ \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny access to .htaccess files, if Apache's document root
location ~ /\.ht {
deny all;
}
# Exclude favicon from the logs to avoid bloating when it's not available
location /favicon.ico {
log_not_found off;
access_log off;
}
}
As AlexeyTen mentioned above, php server port was the problem in /etc/nginx/fastcgi_params I changed:
fastcgi_param SERVER_PORT $server_port;
to:
#fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PORT 80;
and it has resolved my problems!
I recently installed NGINX and PHP-FPM on a Centos6 server. I'm able to view other php pages on my site, but for some reason my index.php file gets downloaded rather than processed like a normal php page.
Here is the nginx config:
# The default server
#
server {
listen 80 default_server;
server_name example.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/html/;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /index.php {
root /var/www/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Try to remove this block:
location = /index.php {
root /var/www/html;
}