I'm trying to make a local webserver with nginx php 7.1 and mariadb on windows WSL.
I tried a lot of things, use Kali, use Debian, use Ubuntu, change nginx port instead of 80, I found a few nginx config that I tried but none worked.
My problem is that php don't process throught nginx.
When I try to load a simple php page <?php echo 'ok'; ?> it load infinitly.
But when I restart php7.1-fpm, the page work ! (One time and only if I was trying to load it)
This is my actual default nginx config file :
server {
listen 32000 default_server;
listen [::]:32000 default_server;
# 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 /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
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.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
# I tried this too :
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When I run php index.php this is working too. But on firefox nothing happen when I load this file. Everything is fine with full html page. I got the nginx welcome page too with no problems.
I don't know where to look anymore. Thanks for reading and if you have any answer, thanks a lot !
Here is mine:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME D:/web/html$fastcgi_script_name;
include fastcgi_params;
try_files = $uri #missing;
}
Also make sure PHP-CGI is running (and on the right port).
Related
i tried to open https://isin.ir/wp-admin/theme-editor.php and customize my theme
i get error
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.
the thing i did
increase max_execution_time in php.ini
add define( 'DISALLOW_FILE_EDIT', false ); to wp-config.php
when i chang theme this problem was solved
hi in my opinion if you use this code your problem fix
server {
listen 4050;
listen [::]:4050;
# 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 /var/www/deltatechco.ir;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name deltatechco.ir www.deltatechco.ir;
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.4-fpm.sock;
# # 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;
}
}
I'm trying to make a Nginx configuration where I can have Angular and Symfony both on the same domain but the Symfony on suburl.
The issue is that I'm getting all the time 404 Not Found for the Symfony Config.
My website has a default redirection for the Login and I'm being redirect to the url but after I'm getting the 404. (test.com/api/connect/azure) is the URL I'm being redirected to.
2022/01/10 15:16:15 [error] 23#23: *3 open()
"/var/www/angular/back/public/connect/azure" failed (2: No such file
or directory)
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/test_com.pem;
ssl_certificate_key /etc/nginx/ssl/test_com.pem.com.key;
server_name test.com;
root /var/www/angular/front/dist;
location /api {
alias /var/www/angular/back/public;
index index.php
try_files $uri /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass php8:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_intercept_errors on;
# 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 $request_filename;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
}
location / {
try_files $uri $uri/ /index.html;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
You have nested your location directives. I also see that you are listening on port 443 but there is no mention of which domain request nginx should respond to.
Consider using subdomains to host the Angular and Symfony applications as follows
angularapp.mydomain.com
symfonyapi.mydomain.com
You should separate the configuration for Angular and Symfony into seprate .conf files.
I have a VPS setup that isn't working properly.
Environment: Ubuntu 18.04, php7.4, postgresql and nginx
The IP address for the server resolves successfully and shows default "Success" page served. The domain I want to use to point to the server does not work, however, and resolves 404. I feel like this is a simple fix but after a day of searching I haven't found it yet.
Help is appreciated!
Troubleshooting:
nslookup on windows resolves domain name to the correct IP address (I can ssh into server with just domain name)
the domain still remains not found when using the domain in my browser. Here is the /etc/nginx/sites-available/temp.domain:
server {
listen 80;
server_name temp.domain;
root /var/www/temp.domain/public_html;
index index.php index.html;
access_log /var/log/nginx/temp.domain.access.log;
error_log /var/log/nginx/temp.domain.error.log;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass unix:/usr/local/var/run/php-fpm.socket;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
default config:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 192.169.0.1; #temp ip address
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.4-fpm.sock;
# # 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;
}
}
had to install php-config and then make sure php.ini has postgresql extensions enabled. Also had to fix the server block in nginx sites-available/default
I've been given an NGNIX server that previously only had Ubuntu 18.04 and NGNIX installed and was used to render a static html site.
I've installed PHP, MySqli ect and configured the sites-available file to get the website up and running. After importing the database from the development site to the live site the website is working perfectly fine as expected apart from one bug.
If I click on a draft page while in 'Split Mode' or 'Preview Mode' I get redirected to the 'Page Not Found' within the admin. If I switch to 'Edit Mode' everything works perfectly fine.
Once I publish the draft page I can then view it in 'Split Mode' or 'Preview mode' perfectly fine.
I'm wondering if it's got something to do with my NGNIX config. I configured my sites-available/default file using the link below:
https://www.nginx.com/resources/wiki/start/topics/recipes/silverstripe/#recipe
here is my ngnix sites-available config file
server {
include mime.types;
default_type application/octet-stream;
#listen 80 default_server;
#listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl on;
ssl_certificate /etc/ssl/certs/certificate.pem;
ssl_certificate_key /etc/ssl/private/key.key;
root ****************
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name ****************;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.php?query_string;
}
error_page 404 /assets/error-404.html;
error_page 500 /assets/error-500.html;
# see caveats
error_page 502 /assets/error-500.html;
error_page 503 /assets/error-500.html;
location ^~ /assets/ {
sendfile on;
try_files $uri =404;
}
location /index.php {
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_buffers 4 32k;
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
When I navigate to /install.php I get no warnings or errors.
Any clues as to what might cause this? Let me know if you need any more information.
I've successfully installed nginx that uses PHP-FPM but unfortunately I'm having some trouble when loading my php files from a different directory. All my files are located in subdirectories in /var/www/html (e.g. all css-files are located in /var/www/html/css, all javascript-files are located in /var/www/html/js, all php-files are located in /var/www/html/php).
According to this, I changed the root directory path for my php files to /var/www/html/php:
server {
listen 80 default_server;
listen [::]:80 default_server;
# 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 /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php home.php;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/php;
include snippets/fastcgi-php.conf;
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
Unfortunately, when accessing my nginx server using my web browser, I'm getting error 403 (Forbidden). When accessing my index.php (http://192.168.2.109/index.php) directly, everything works fine. So, I think it means that the file permissions are correct but nginx isn't able to index the /var/www/html/php directory. Furthermore, /var/log/nginx/error.log includes:
2017/05/28 07:49:56 [error] 13678#13678: *1 directory index of "/var/www/html/" is forbidden, client: 192.168.2.101, server: _, request: "GET / HTTP/1.1", host: "192.168.2.109"
I already tried to enable autoindex and add the index specifier in the "location ~ .php$ {" section without success. The result is the same :(
Does anyone has an idea what I'm doing wrong/missing here? All suggestions in Nginx 403 error: directory index of [folder] is forbidden didn't solve my problem.
The problem are easy:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/php;
include snippets/fastcgi-php.conf;
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
As I can read, when you request a *.php file, you change the root address. But, when you request "default index", you are requesting /, not a .php
You need a new location, for change root path on / request. Try to use this:
location = / {
root /var/www/html/php;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
Maybe, on this config, you need to put a "rewrite index.php;", but I didn't know because I've never test this configuration.
Don't think my new location order (location = /) is the same as yours (location /), because my order, with the equal sign, only apply when you request exactly the "main" location without any parameter.