Start Phoenix app with cowboy server on different port - cowboy

Is it possible to start locally a few Phoenix apps on different ports from the console using some command like mix phoenix.server --port=4001? This one does not work, of course, but, maybe, there is similar way.

Yep! Make sure you set the mix config to reference the env port, i.e.
config :my_app, MyApp.Endpoint,
http: [port: {:system, "PORT"}],
Then from the terminal:
$ PORT=4001 mix phoenix.server
$ PORT=4002 mix phoenix.server
$ PORT=4003 mix phoenix.server

Edit your config/dev.exs and change the Endpoint http port like the following:
config :my_app, MyApp.Endpoint,
http: [port: System.get_env("PORT") || 4000],
This allows the port to be set, or left as the default 4000:
PORT=4002 mix phoenix.server # to run on port 4002
mix phoenix.server # to run on port 4000
This answer was described by #chris-mccord on github.

This was needed for me as a solution since my issue was that I needed to let C9.io dictate the port, for me, adding this code to the dev.exs file solved the problem:
config :my_app, MyApp.Endpoint,
http: [port: {:system, "PORT"}],
and then in the Terminal, I just needed to run the server as normal:
mix phoenix.server

Related

How to run Mercure in production with Apache

I have a Symfony project on an Apache server that uses Mercure and I try to setup the Mercure hub in production.
To run the Mercure hub in production, I extract the archive mercure_0.6.2_Linux_x86_64.tar.gz (https://github.com/dunglas/mercure/releases) into a subfolder mercure at the root of my project.
Then I run the command:
JWT_KEY='myJWTKey' ACME_HOSTS='example.com' ./mercure
with my informations
But the hub doesn't run with this error:
FATA[0000] listen tcp :443: bind: permission denied
I saw a similar question (How to run Mercure in production)
but the proposed answer uses ADDR to change port, and according to the documentation, "Let's Encrypt only supports the default port: to use Let's Encrypt, do not set this variable.".
How do I run Mercure in production?
Here are the steps I did to resolve my problem :
I run Mercure with this command:
JWT_KEY='aVerySecretKey' ADDR='myhub.com:3000' CORS_ALLOWED_ORIGINS='https://mywebsite.com' DEBUG=1 ALLOW_ANONYMOUS=1 ./mercure
So, Mercure run here: http://myhub.com:3000.
I use Apache as a proxy with this parameters:
ProxyPass / http://myhub.com:3000/
ProxyPassReverse / https://myhub.com/
So now, I can access the hub in HTTPS here https://myhub.com/hub from my domain https://mywebsite.com.
Thanks to dunglas, the author of Mercure.
I don't know if this is helpful, but after a lot of struggle I got Mercure working on a live server like this. (I'm using port 9090 throughout.) In Apache domain conf:
ProxyPass /hub/ http://localhost:9090/
ProxyPassReverse /hub/ http://localhost:9090/
In Javascript:
new URL('https://www.example.com/hub/.well-known/mercure');
In Symfony:
MERCURE_PUBLISH_URL=https://www.example.com/hub/.well-known/mercure
Being careful not to confuse MERCURE_JWT_TOKEN with MERCURE_JWT_SECRET.
From root, running Mercure server like this for testing:
docker run -e JWT_KEY='!ChangeMe!' -e DEMO=1 -e ALLOW_ANONYMOUS=1 -e CORS_ALLOWED_ORIGINS='*' -e PUBLISH_ALLOWED_ORIGINS='*' -p 9090:80 dunglas/mercure
So now everything is working, without https / 443 problems.

Minishift: Could not resolve: *.192.168.64.2.nip.io

I have installed minishift on OSX with brew:
brew cask install minishift-beta
...
$ minishift version
Minishift version: 1.0.0
I have sucessfuly started minishift, and created node-ex example application and exported it:
$ oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
nodejs-ex nodejs-ex-myproject.192.168.64.2.nip.io nodejs-ex 8080-tcp None
However I can not reach .192.168.64.2.nip.io:
$ curl nodejs-ex-myproject.192.168.64.2.nip.io
curl: (6) Could not resolve host: nodejs-ex-myproject.192.168.64.2.nip.io
$ dig +short nodejs-ex-myproject.192.168.64.2.nip.io
$
All is working with minishift web console and oc command, but I can not reach the application domain.
Thank you #enj. The explanation at http://nip.io is clear about how it works.
I have seen that queries to 8.8.8.8 and to my ISP DNS are resolved to my private IP. But it is my router (my primary DNS) which do respond nip.io
My router run DD-WRT and has enabled
Rebind protection Discard upstream RFC1918 responses
then I add nip.io at
Domain whitelist nip.io
and now I resolve queries:
≻ dig +short test.10.0.0.1.nip.io
10.0.0.1
Is something on your machine or network blocking DNS queries to nip.io?
When playing with Minishift at home, where I am connected to the internet via Deutsche Telekom's VDSL and Speedport-Router, I cannot resolve these xip.io or nip.io addresses.
My workaround is to put 8.8.8.8 into /etc/resolv.conf
I had the same issue on Windows 10. My workaround was to add an entry in C:\Windows\System32\drivers\etc\hosts file. Here is an example
192.160.90.101 nodejs-ex-nodejs-echo.192.160.90.101.nip.io # needed for minishift to work

Error 'tunneling socket' while executing npm install

I'm getting the error shown below while trying to execute 'npm install' command.
Error: tunneling socket could not be established, cause=connect ECONNREFUSED 10.232.207.137:8080
What do I miss?
If you are behind a proxy, set it correctly in npm.
>npm config set proxy http://proxyhost:proxyport
>npm config set https-proxy http://proxyhost:proxyport
Notes:
For SSL/https proxies, the protocol in URL should be http not https
If your set up is on a Docker/Vagrant instance or a hosted VM, use IP address instead of hostname for proxy as the later might not be resolvable.
If there is no proxy , remove proxy config from npm
>npm config set proxy null
>npm config set https-proxy null
I know this is way too late but if someone has a similar issue in the future and you are sure you have no proxy set but you have an environment variable called http_proxy. Please delete it and try again. I had set a proxy for Fiddler.
according to this it's proxy isssues, try to disable ssl and set registry to http instead of https . hope it helps!
npm config set registry=http://registry.npmjs.org/
npm config set strict-ssl false
Following commands may solve your issue:
npm config set proxy false
npm cache clean
It solved my same issue.
In my case helped delete .npmrc config file
rm ~/.npmrc
Removing the proxy settings resolved the issue:
If you are no using any proxy:
npm config rm proxy
npm config rm https-proxy
If you are using Proxy:
npm config set proxy http://proxyhostname:proxyport
npm config set https-proxy https://proxyhostname:proxyport
Hopefully this will solve your problem :)
remember to set you username and password if required:
http://USERNAME:passwd#proxyserver.co.uk:8080
Example:
npm config set proxy http://USERNAME:passwd#proxyserver.co.uk:8080
If in case you are using ubuntu trusty 14.0 then search for Network and select Network Proxy and make it none. Now proxy may still be set in system environment variables. check
env|grep -i proxy
you may get output as
http_proxy=http://192.168.X.X:8080/
ftp_proxy=ftp://192.168.X.X:8080/
socks_proxy=socks://192.168.X.X:8080/
https_proxy=https://192.168.X.X:8080/
unset these environment variable as:
unset(http_proxy)
and in this way unset all. Now run npm install ensuring user must have permission to make node_modules folder where you are installing module.
Next to what has described #Roshith in his answer here:
If you are behind a proxy, set it correctly in npm.
npm config set proxy http://proxyhost:proxyport
npm config set https-proxy http://proxyhost:proxyport
I had to change also the file ~.bashrc which also contained a wrong proxy setting in my case. I changed those settings here:
export HTTP_PROXY="http://proxyhost:proxyport"
export HTTPS_PROXY="http://proxyhost:proxyport"
Use the following command to verify the proxy settings:
env | grep -i proxy
An important point to remember is if you're behind a corporate firewall and you get you're corporate proxy settings from a .pac file, then be sure to use the value for global proxy.
I lost a day trying to make this work.
Worked with this steps.
I opened Fiddler and checked the option Rules > Automatically Autenticate.
After, search for file .npmrc, usually in c:\users\ and used it as configuration:
registry=https://registry.npmjs.org/
proxy=http://username:password#127.0.0.1:8888
https-proxy=http://username:password#127.0.0.1:8888
http-proxy=http://username:password#127.0.0.1:8888
strict-ssl=false
ca=null
Hope help someone!
I also ran into the similar issue and was using CNTLM for proxy configuration. In my case HTTP_PROXY and HTTPS_PROXY are taking higher precedence over http_proxy and https_proxy so be aware of changing all proxy variables.
env|grep -i proxy
and make sure all of the below proxy variables should point to the same proxy.
HTTP-PROXY = "http://localhost:3128"
HTTPS-PROXY = "https://localhost:3128"
HTTPS_PROXY = "http://localhost:3128"
HTTP_PROXY = "http://localhost:3128"
PROXY = "http://localhost:3128"
http-proxy = "http://localhost:3128"
http_proxy = "http://localhost:3128"
https-proxy = "https://localhost:3128/"
https_proxy = "https://localhost:3128"
proxy = "http://localhost:3128/"
I know some variables are unneccessary but I'm not sure which is using what.
I had this same error when trying to install Cypress via npm. I tried many of the above solutions as I am behind a proxy, but was still seeing the same error. In the end I found that my WIndows system configuration(can be checked by entering 'set' in command prompt) had HTTP and HTTPS proxys set that differed from the ones vonfigure in npm. I deleted these proxys and it downloaded staright away.
I have faced similar issue and none of the above solution worked as I was in protected network.
To overcome this, I have installed "Fiddler" tool from Telerik, after installation start Fiddler and start installation of Protractor again.
Hope this will resolve your issue.
Thanks.
If you using gnome, and turned off the proxy at the network level, you also need to make sure you don't have proxy enabled in your terminal
➜ gconftool-2 -a /system/http_proxy
host = http://localhost/
port = 2000
use_http_proxy = false
use_authentication = false
authentication_password =
authentication_user =
ignore_hosts = [localhost,127.0.0.0/8]
You can drop it with
gconftool-2 -t string -s /system/http_proxy/host ""
gconftool-2 -u /system/http_proxy/port
gconftool-2 -u /system/http_proxy/host
unset http_proxy
After looking at all of the answers, the one that helped me was providing proxy values in-line with the install command. One of my frustrations was adding the domain to my username. This is not needed. I used the following example to install a specific version of Angular:
npm install -g #angular/cli#1.7.3 --proxy "http://username:password#proxy_server:proxy_port" --registry http://registry.npmjs.org
I spent days trying all the above answers and ensuring I had the proxy and other settings in my node config correct. All were and it was still failing. I was/am using a Windows 10 machine and behind a corp proxy.
For some legacy reason, I had HTTP_PROXY and HTTPS_PROXY set in my user environment variables which overrides the node ones (unknown to me), so correcting these (the HTTPS_PROXY one was set to https, so I changed to HTTP) fixed the problem for me.
This is the problem when we can have the Same variables in Multiple places, you don't know what one is being used!
npm config set registry http://registry.npmjs.org/
above code solved my issue :)
I faced similar and tried some of the techniques mentioned here. To overcome,
I performed a cleanup of duplicate entries in c:\users\<user name>\.npmrc
Hope it helps someone.
Thanks,
If you are using a VPN on a secure network (like a VPN for working-from-home), you may have an issue with permissions. For me, I solved this using sudo to initialize a ReactJS development environment...
sudo npm install
If you're trying all of the above and still having issues, make sure your local path does not contain spaces. (There are ways to allow spaces but mine wasn't set up that way.) In my case, I was using MAMP with a Server Document root of /Users/myusername/My Site. Changing this to /Users/myusername/My-Site resolved the issue.
For windows
If you are not using any proxy (search proxy in start menu search bar to see settings) then
npm config set proxy null
npm config set https-proxy null
npm cache clean
If above does not work, you might need to do it by force, but only if you are sure cache clean does not cause any other installation problem for you
npm cache clean --force
delete http_proxy from environment variables
Try now and it should be fine

How to configure redis.conf on openshift for redis

Have a problem that by following the repo
https://github.com/razorinc/redis-openshift-example
When i start redis-server, it says "[12010] 25 Mar 20:14:53 # Opening port 6379: bind: Permission denied"
I tried to change port 0 to port 3128 but still get the same error....not sure why
--Update
When i tried to upgrade to redis 2.6 and uses --port parameter to bind to 3128, it still says
remote: [6844] 25 Mar 20:49:00.206 # Opening port 3128: bind: Permission denied
Here's the OpenShift forum thread with suggested modifications: https://www.openshift.com/forums/openshift/how-to-configure-redisconf-on-openshift-for-redis
Looks like calling redis-server uses default conf parameters that won't work well in the OpenShift gear environment so making the suggested changes to the redis.conf file and passing it into redis-server is the way to go. There are suggestions for a pre-start and pre-stop hook as well.

http_proxy setting

I know this is simple.. I am jus missing something.. I give up!!
#!/bin/sh
export http_proxy='http://unblocksitesnow.info'
rm -f index.html*
strace -Ff -o /tmp/mm.log -s 200 wget 'http://slashdot.org'
I have used different proxy servers.. to no avail.. I get some default page..
In /etc/wgetrc use_proxy = on
Actually I am trying to use this setting(http_proxy) with python's urllib2. It access some default page as well..
strace - does a dns lookup of the proxy server
GET http://slashdot.org/ HTTP/1.0\r\nUser-Agent: Wget/1.11.4\r\nAccept: /\r\nHost: slashdot.org\r\n\r\n
Any pointers??
For some apps, HTTP_PROXY is case sensitive. It's best to set it in upper case.
# export HTTP_PROXY=http://server/
or
# export HTTP_PROXY=http://server:8888/
The problem was I was using proxy sites. These sites expect you to send GET request to the proxy site (with the target site as parameter in URL or whatever site specific mechanisms they implement).
I was looking for proxy sites like http://www.proxy4free.com/page1.html
I connect to their respective ports and send a get request to the original target site..
Often you need a port with the proxy-server, for example:
export http_proxy=http://unblocksitesnow.info:30000
Also, the single quotes are not needed.
On Debian/Ubuntu if you need apt-get via the proxy you will also need to update
/etc/apt/apt.conf
If the file doesnt exist, create it and apt-get update to confirm
As well as export http_proxy="<ADD>:<PORT>"