Nginx is using both port 80 and 8080 - php

I changed listening port of nginx from 80 to 8080 in /etc/nginx/site-enabled/default but when in netstat -plnt result it use both of them:
here is my nginx default config
server {
listen 8080 default;
root /home/mosi/workspace;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
Problem solved
Since I had many other config file, I just added port listening line in other configs and It work correct now
Tahnks

Related

NGINX access multiple sites same IP url

I would like to know how I can have several sites on Nginx and be able to access each of them with the same IP (without the domain, since I am doing tests in a laboratory locally).
I have the server on a separate PC and I access it remotely from my computer using the IP. Both are on the same LAN.
In the directory /var/www/ I have two sites 'nextcloud' and 'phpmyadmin'. I would like to be able to enter both by placing (for example) 192.168.1.14/nextcloud and 192.168.1.14/phpmyadmin. Or having any other project in the www directory.
I tried all the solutions I found, but none of them worked for me. When I enter phpmyadmin for example, it gives me to download the page instead of entering it.
Within /etc/nginx/sites-enabled I have the two files, one from nextcloud:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/nextcloud/;
index index.php index.html index.htm;
server_name localhost;
client_max_body_size 512M;
fastcgi_buffers 64 4K;
location / {
root /var/www/nextcloud;
rewrite ^ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
And that of phpmyadmin:
server {
listen 80;
listen [::]:80;
root /var/www/phpmyadmin/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
Try creating two test folders in /var/www/ (test1 and test2), each with an index.html file inside and modifying the nginx default file, but it didn't work for me either
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
index index.html;
location / {
return 410; # Default root of site won't exist.
}
location /test1/ {
alias /var/www/test1/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
location /test2/ {
alias /var/www/test2/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
}
As I said, I tried different solutions. Another problem I had was that it only redirected me to nextcloud, although I put phpmyadmin in the url. And the previous one that I already mentioned, that when I enter, download the index.php. Thank you.
Sorry for my English.
Simple add nextcloud.my and phpmyadmin.my to your .hosts file and listen domain name in Nginx.
The option that you proposed can also be made to work, but it is full of bugs and difficulties can occur during the transfer to work server.

PHP not running on nginx with Debian 8

I just configured my Debian 8 server with nginx. I can browse html files. I use let's encrypt which works succesfully, also with redirecting http to https automatically.
What does not work is PHP. Also a simple info.php file with
<?php
phpinfo();
?>
does not work.
On browser client my error message is:
404 Not Found nginx/1.6.2
Nginx' error log shows this:
2018/05/29 19:22:57 [error] 1879#0: *1592 open() "/usr/share/nginx/html/info.php" failed (2: No such file or directory), client: ip_address, server: , request: "GET /info.php HTTP/1.1", host: "domain"
My nginx configuration is:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
server_name my-server.de www.my-server.de;
return 301 https://$server_name$request_uri;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
}
Even if i move info.php to /usr/share/nginx/html then the client browser just downloads the info.php file.
I went through all steps in this guide. But still it isn't working. So how to fix that?
You have not added in SSL listen port 443, and ssl config of let's encrypt, please comment 301 redirect, test PHP, than go for SSL configuration see https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8
I have seen you have added SSL configuration, you need fix as below nginx configuration, after redirect, PHP should be configured on 443 not on 80.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name my-server.de www.my-server.de;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
This is what I'm using:
upstream php {
server 127.0.0.1:9000;
server unix:/var/run/php5-fpm.sock down;
}
location ~* \.php$ {
root /var/www/html/;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 180;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass php;
fastcgi_index index.php;
}

nginx with php-fpm in https returns blank page in php

I've successfully setuped nginx with php-fpm (with http and https),
but when i run a php file in https connection i goa q blank page.
However running php file in http works fine,i am using the same php-fpm configuration for http and https
nginx-configuration for php-fpm(http and https)
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
index index.php index.html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
SSL configuration
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name localhost;
root /var/www/html/cushbu.com/public;
}
Note.
Running .html file in https returns ouput
eg:
https://<ip>/test.html //returns output
https://<ip>/test.php //returns blank output.
http://<ip>/test.php //returns output

nginx and php5-fpm works only with ip address

I'm using Ubuntu 13 and I've installed nginx and php5-fpm; before that I had PHP5 and apache installed; which I removed
/etc/php5/fpm/pool.d/www.conf
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
nginx config file :
upstream php {
server unix:/var/run/php5-fpm.socket;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
When I try
http://local.host/info.php
It downloads the info.php file instead of executing the file
But when I try:
http://my.ip.address/info.php
it shows the phpinfo() function
where is the problem ?
You could try changing you config a bit:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
//fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
and your www.conf:
listen = localhost:9000
;listen = /var/run/php5-fpm.sock
Change line to server_name localhost local.host 127.0.0.1; (are you sure http://local(dot)host is not a typo?)
Check /etc/hostnames and if it differs from above, add it in too. Also check that you dont have another entry server{ ... } entry that listens to same port 80.
Check the folder /etc/nginx/sites-enabled/, the default filename also contains server{...} parameters. The http{...} block is found in /etc/nginx/nginx.conf and sometimes may contain the server{...} block.

NGINX change phpMyAdmin port within a location block

I have my phpMyAdmin setup as follows. This is within the server block of the default in sites-available and sites-enabled.
How can I change the port to say 8003 within the location block or somewhere without affecting the function of the port 80?
server{
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
[..........]
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
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;
}
[..........]
}
You can't set a port in a location block. It wouldn't make sense because the client is connected already when a location is processed. You can make a new server block though, listening on the port you want, and put the location-block in question in the new server block.

Categories