The LNMP(linux nginx mysql php^_^) environment based on docker, all of which I am in a container.
At present, xdebug can be used normally.
But i need enter code herexdebug.remote_host = visitor IP and our IP is constantly changing.
This is an awkward situation.
And if i set xdebug.remote_connect_back = 1 to let xdebug handle the automatic return of IP.
Docker's container is started in the default bridge mode, so the IP obtained by PHP is the bridge IP.
That is: similar to 172.0.0.1, the IP address of the real client cannot be obtained, so xdebug cannot return correctly.
Xdebug.log logs also have records:
Log opened at 2018-07-29 07:39:59
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Remote address found, connecting to :9001.
W: Creating socket for ':9001', getaddrinfo: No such file or directory.
E: Could not connect to client. :-(
Log closed at 2018-07-29 07:39:59
This problem puzzled for a long time, still hope ,please not stint grant instruction! Thank you very much
This is my nginx host conf
server {
listen 80;
server_name test.lh.XXX.com;
access_log /var/log/nginx/access_XXX_log;
error_log /var/log/nginx/error_XXX_log;
index index.html index.htm index.php index.phtml;
client_max_body_size 100m;
set $public_root /home/xxx/www/xxx_xxx_www/public;
root $public_root;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?/$1 last;
}
location / {
try_files $uri $uri/ $uri=404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This is my nginx fastcgi_param
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
Related
I have two docker containers as below:
nginx ==> working as proxy web server (nginx web server)
dist ==> working as a php-fpm container
And this is my dist.conf:
server {
server_name dist.me.com;
root /var/www/html;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass dist:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/dist_error.log;
access_log /var/log/nginx/dist_access.log;
}
The issue is if I enter dist.me.com, it shows my index.php contents fine. But if I enter dist.me.com/index.php or dist.me.com/index2.php, I get error 404 Not Found.
I tried changing some values of conf file but it did not help me.
Both index.php and index2.php exist in /var/www/html path.
Your existing dist.conf is designed to block URIs ending with .php. The internal directive prevents a location from being directly accessed, and there is also a location which explicitly returns 404 for any URI ending with .php.
You need to change the location rule, remove the internal directive, and delete the location block which follows it.
For example, replace location ~ ^/index\.php(/|$) { ... } and location ~ \.php$ { ... } with the single location block as follows:
location ~ \.php(/|$) {
fastcgi_pass dist:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
I am trying to connect to a proxypass in docker I have setup but I keep getting:
8#8: *1 api.example.local could not be resolved (3: Host not found)
I can access the proxy by going to http://api.example.com in my browser, but not if I go through the nginx proxy pass. My nginx is as follows, and please note that:
Have ipv6 disabled
I am resolving to 127.0.0.11
server {
listen 80;
server_name api.example.local;
resolver 127.0.0.11 ipv6=off;
location / {
root /code/api/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?rt=$uri&$args;
}
location ~ \.php$ {
root /code/api/public_html/;
fastcgi_pass php:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param ENV development;
fastcgi_param HTTPS off;
fastcgi_read_timeout 9600;
}
}
server {
index index.php index.html;
server_name www.example.local;
resolver 127.0.0.11 ipv6=off;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code/main/public_html;
location / {
root /code/main/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?rt=$uri&$args;
}
location /api {
resolver 127.0.0.11 ipv6=off;
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Fowarded-Host $host;
set $upstream api.example.local;
proxy_pass http://$upstream;
proxy_connect_timeout 60;
proxy_redirect off;
}
location ~ \.php$ {
root /code/main/public_html/;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param ENV development;
fastcgi_param HTTPS off;
fastcgi_read_timeout 300;
}
}
I also have the domains in my /etc/hosts. The OS is Ubuntu 18.04.
127.0.0.1 localhost
127.0.1.1 my-comp
127.0.0.1 www.example.local
127.0.0.1 api.example.local
What can I be doing wrong?
The nginx container and the upstream server need to be on the same docker network.
Example:
Assuming the nginx container is exposed ports 443 on the bridge, create a docker network called nginx-network and join it to that network.
Assuming also the upstream server is a container called ‘mysite’, join that container to the nginx-network, nginx will then be able to resolve the dns ‘mysite’.
I'm using Docker for the first time, trying to build an NGINX proxy (also first time with NGINX). I've seen multiple guides that all seem to suggest I'm on the right path, but when I run the image, I get duplicate listen options for [::]:80 in /etc/nginx/conf.d/site.conf.
site.conf:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name gamersplane.local;
root /var/www;
index dispatch.php;
location / {
try_files $uri /dispatch.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /dispatch.php =404;
fastcgi_pass api:9000;
fastcgi_index dispatch.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
}
api.conf:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name api.gamersplane.local;
root /var/www/api;
index dispatch.php;
location / {
try_files $uri /dispatch.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /dispatch.php =404;
fastcgi_pass api:9000;
fastcgi_index dispatch.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
}
I have two compose files:
docker-compose.yal
proxy:
build:
context: ./nginx
dockerfile: Dockerfile
container_name: gamersplane-proxy
ports:
- 80:80
volumes:
- ../:/var/www
docker-compose.dev.yml
proxy:
volumes:
- ./nginx/dev/site.conf:/etc/nginx/conf.d/site.conf
- ./nginx/dev/api.conf:/etc/nginx/conf.d/api.conf
You need to remove ipv6_only=on, according to the documentation:
This parameter is turned on by default. It can only be set once on start.
So no need to add it to your config
Nevermind Guys. It has been a simple configuration issue confusing key and cert
I'm trying to setup nginx inside a docker container.
It throws the error:
nginx: [emerg] PEM_read_bio_X509_AUX("/ssl/nginx.key") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)
I am well aware this is usually caused by a Syntax error, but:
openssl rsa -noout -text -in /ssl/nginx.key
seems to be working fine as now error message is thrown.
Is anybody aware of this issue and able to help me or replicate the error?
Have a nice weekend :)
Environment(of course ran in container):
nginx -v
nginx version: nginx/1.13.7
docker --version
Docker version 17.12.0-ce, build c97c6d6
cat nginx.conf
user www-data; ## Default: nobody
worker_processes auto;
pid /run/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 4096; ## Default: 1024
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
server {
listen 80;
listen 443 ssl;
ssl_certificate /ssl/nginx.key;
ssl_certificate_key /ssl/nginx.crt;
root /web/phabricator/webroot;
index index.html index.htm index.php;
server_name _;
location / {
index index.php;
rewrite ^/(.*)$ /index.php?__path__=/$1 last;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
#required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
#variables to make the $_SERVER populate in PHP
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
}
}
}
As you've pointed out, the error is in mixing up the .key and .crt file.
It's easily done.
ssl_certificate /ssl/nginx.key;
ssl_certificate_key /ssl/nginx.crt;
The files just need to be swapped round:
ssl_certificate /ssl/nginx.crt;
ssl_certificate_key /ssl/nginx.key;
I have a Rails app configured with nginx with its root at /var/www/apps/example/current/public. It's accessed at https://www.example.com. That all works great. I decided to add a blog, and I wanted to go with Wordpress. I installed it in a different directory on the server, /var/www/apps/blog, and I want to be able to access it by going to https://www.example.com/blog
Below is my nginx config:
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/certs/example.com.pem;
ssl_certificate_key /etc/ssl/certs/example.com.key;
server_name www.example.com;
root /var/www/apps/example/current/public;
passenger_enabled on;
rails_env production;
client_max_body_size 100M;
client_body_buffer_size 256k;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /blog {
root /var/www/apps;
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
I can navigate to example.com/blog and it takes me there without any issues. The problem comes when I enable pretty URLs and try to view a post. It circumvents the /blog directory and hits my Rails app, ending up with a 404. I see the following error in /var/log/nginx/error.log:
2016/06/30 17:24:32 [error] 7035#0: *20 "/var/www/apps/blog/hello-world/index.html" is not found (2: No such file or directory), client: 199.27.128.198, server: www.example.com, request: "GET /blog/hello-world/ HTTP/1.1", host: "www.example.com", referrer: "https://www.example.com/blog/"
Adding an index index.php directive doesn't fix the problem, it merely then states that /var/www/apps/blog/hello-world/index.php is not found instead.
Any ideas? I'm stumped.
try_files $uri=404; is not enough for pretty permalinks.
To enable pretty permalinks, you need to change it to:
location /blog {
root /var/www/apps/blog;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Or, try non-root try_files redirect:
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Here's a quick guide setting up wordpress with rails