question stringlengths 11 28.2k | answer stringlengths 26 27.7k | tag stringclasses 130
values | question_id int64 935 78.4M | score int64 10 5.49k |
|---|---|---|---|---|
I am writing some webservices returning JSON data, which have lots of users.
What are the benefits of using Nginx in front my server compared to just using the go http server?
| It depends.
Out of the box, putting nginx in front as a reverse proxy is going to give you:
Access logs
Error logs
Easy SSL termination
SPDY support
gzip support
Easy ways to set HTTP headers for certain routes in a couple of lines
Very fast static asset serving (if you're serving off S3/etc. though, this isn't that r... | NGINX | 17,776,584 | 107 |
I have several sets of static .html files on my server, and I would like use nginx to serve them directly. For example, nginx should serve an URI of the following pattern:
www.mysite.com/public/doc/foo/bar.html
with the .html file that is located at /home/www-data/mysite/public/doc/foo/bar.html. You can think of foo a... | It should work, however http://nginx.org/en/docs/http/ngx_http_core_module.html#alias says:
When location matches the last part of the directive’s value:
it is better to use the root directive instead:
which would yield:
server {
listen 8080;
server_name www.mysite.com mysite.com;
error_log /ho... | NGINX | 12,806,893 | 106 |
I want to write some more complex conditions in my Nginx configuration files but I'm not sure of the syntax and can't find docs describing what you can do beyond the basics in the examples and I can't seem to find this on the Nginx forums or on the mailing list.
For example, is it possible for me to have an unless cond... | So I'm a newbie to nginx, and had this same question. Turns out the syntax of the language as mentioned above is both custom and actually quite simple. The syntax is captured in a section in the NGINX docs, and repeated here for convenience:
nginx consists of modules which are controlled by directives
specified in t... | NGINX | 2,936,260 | 103 |
I have a problem with nginx. I tried different solutions, but for me nothing work.
That is my error:
4 root@BANANAS ~ # sudo service nginx restart :(
Restarting nginx: nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:443 failed (98: Addre... | Probably other process is using specified port:
sudo netstat -tulpn
Get the PID of the process that already using 443. And send signal with kill command.
sudo kill -2 <PID>
sudo service nginx restart
Aternatively you can do:
sudo fuser -k 443/tcp
Make sure you dont use old syntax:
server {
listen :80;
liste... | NGINX | 42,303,401 | 101 |
I have a Rails application that I want to deploy using Docker on an Ubuntu server. I have the Dockerfile for the application already set up, right now I want to view the nginx conf in its container.
I ran the command below to start an nginx container in an interactive mode:
docker run -i -t nginx:latest /bin/bash
Righ... | Try restarting Docker.
One of these should work:
sudo service docker restart
sudo /etc/init.d/docker restart
sudo snap restart docker
Even in cases where Docker never worked before, some commenters said this was helpful.
| NGINX | 61,567,404 | 100 |
Is there any benchmark or comparison which is faster: place nginx in front of node and let it serve static files directly or use just node and serve static files using it?
nginx solution seems to be more manageable for me, any thoughts?
| I'll have to disagree with the answers here. While Node will do fine, nginx will most definitely be faster when configured correctly. nginx is implemented efficiently in C following a similar pattern (returning to a connection only when needed) with a tiny memory footprint. Moreover, it supports the sendfile syscall to... | NGINX | 9,967,887 | 100 |
I am using Laravel web framework on my ubuntu 14.04 server and Nginx web server, I have this error when I try to upload a file using Laravel to the server.
my upload directory is on the public/uploads folder that has 777 permission.
| The GD Graphics Library is for dynamically manipulating images.
For Ubuntu you should install it manually:
PHP8.0: sudo apt-get install php8.0-gd
PHP8.1: sudo apt-get install php8.1-gd
PHP8.2: sudo apt-get install php8.2-gd
PHP8.3: sudo apt-get install php8.3-gd
That's all, you can verify that GD support loaded:
php ... | NGINX | 34,009,844 | 99 |
I'm new to NGINX and I'm trying to setup minimal working thing. So I trying to run aiohttp mini-app with nginx and supervisor (by this example). But I can't configure Nginx right and getting the following error:
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:1
Here is full defa... | I am assuming that you have http in your /etc/nginx/nginx.conf file which then tells nginx to include sites-enabled/*;
So then you have
http
http
server
As the http directive should only happen once just remove the http directive from your sites-enabled config file(s)
| NGINX | 43,643,829 | 97 |
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if (-f $request_filename) {
access_log off;
expires 30d;
break;
}
if (!-f $request_filename) {
proxy_pass http://... | Use try_files and named location block ('@apachesite'). This will remove unnecessary regex match and if block. More efficient.
location / {
root /path/to/root/of/static/files;
try_files $uri $uri/ @apachesite;
expires max;
access_log off;
}
location @apachesite {
proxy_set_header X-Real-IP $remot... | NGINX | 869,001 | 97 |
I am using Nginx in front of 10 mongrels.
When I make a request with size larger then 2900 I get back an:
error code 414: uri too large
Does anyone know the setting in the nginx configuration file which determines the allowed uri length ?
| From: http://nginx.org/r/large_client_header_buffers
Syntax: large_client_header_buffers number size ;
Default: large_client_header_buffers 4 8k;
Context: http, server
Sets the maximum number and size of buffers used for reading large client request header. A request line cannot exceed the size of one buffer, or the ... | NGINX | 1,067,334 | 96 |
I uploaded react.js application to a server. I'm using nginx server. Application is working fine. But when I go to another page & refresh, the site is not working. It's showing a 404 Not found error.
How can I solve this?
| When your react.js app loads, the routes are handled on the frontend by the react-router. Say for example you are at http://a.com. Then on the page you navigate to http://a.com/b. This route change is handled in the browser itself. Now when you refresh or open the url http://a.com/b in the a new tab, the request goes t... | NGINX | 43,555,282 | 95 |
Update II
It's now July 16th, 2015 and things have changed again. I've discovered this automagical container from Jason Wilder: https://github.com/jwilder/nginx-proxy and it solves this problem in about as long as it takes to docker run the container. This is now the solution I'm using to solve this problem.
Update
It'... | @T0xicCode's answer is correct, but I thought I would expand on the details since it actually took me about 20 hours to finally get a working solution implemented.
If you're looking to run Nginx in its own container and use it as a reverse proxy to load balance multiple applications on the same server instance then the... | NGINX | 27,912,917 | 95 |
I use SetEnv in Apache to set some variables in virtualhosts that I recover in PHP using $_SERVER[the_variable].
Now I am switching to Perl Catalyst and Nginx, but it seems that the "env" directive in Nginx is not the same. It does not work. How can it be accomplished?
Here is the background picture, just in case someo... | location / {
...
fastcgi_param APPLICATION_ENV production;
fastcgi_param APPLICATION_CONFIG user;
...
}
but it's for PHP-CGI
| NGINX | 8,098,927 | 95 |
I have my config setup to handle a bunch of GET requests which render pixels that work fine to handle analytics and parse query strings for logging. With an additional third party data stream, I need to handle a POST request to a given url that has JSON in an expected loggable format inside of it's request body. I don'... | This solution works like a charm:
http {
log_format postdata $request_body;
server {
location = /post.php {
access_log /var/log/nginx/postdata.log postdata;
fastcgi_pass php_cgi;
}
}
}
I think the trick is making nginx believe that you will call a CGI script.
Edit 2022-0... | NGINX | 4,939,382 | 95 |
I'd love to use nginx to serve a website with multiple domain names and SSL:
webmail.example.com
webmail.beispiel.de
Both use the same vhost so I only set the server_name twice.
Problem is, that I need nginx to serve the correct ssl certificate for each domain name.
Is this possible with one vhost or do I need to set... | Edit November 2014: the initial answer is not correct and is incomplete ; it needed a refresh! here it is.
Basically, there are two cases
You own a wildcard certificate (or multi-domains certificate)
In this case, you may use several vhosts listening to the same IP address/https port, and both vhosts use the same ce... | NGINX | 14,434,120 | 93 |
I'm installing a previously built website on a new server. I'm not the original developer.
I've used Gunicorn + nginx in the past to keep the app alive (basically following this tutorial), but am having problems with it here.
I source venv/bin/activate, then ./manage.py runserver 0.0.0.0:8000 works well and everything ... | Your error message is
ImportError: No module named 'myproject.wsgi'
You ran the app with
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
And wsgi.py has the line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
This is the disconnect. In order to recognize the project as myproject.wsgi the paren... | NGINX | 39,460,892 | 92 |
Trying to deploy my first portal .
I am getting 502 gateway timeout error in browser when i was sending the request through browser
when i checked the logs , i got this error
2014/02/03 09:00:32 [error] 16607#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 14.159.131.19, server... | I don't think that solution would work anyways because you will see some error message in your error log file.
The solution was a lot easier than what I thought.
simply, open the following path to your php5-fpm
sudo nano /etc/php5/fpm/pool.d/www.conf
or if you're the admin 'root'
nano /etc/php5/fpm/pool.d/www.conf
T... | NGINX | 21,524,373 | 92 |
I'm using Nginx as a proxy to filter requests to my application. With the help of the "http_geoip_module" I'm creating a country code http-header, and I want to pass it as a request header using "headers-more-nginx-module". This is the location block in the Nginx configuration:
location / {
proxy_pass ... | If you want to pass the variable to your proxy backend, you have to set it with the proxy module.
location / {
proxy_pass http://example.com;
proxy_set_header Host example.com;
proxy_set_header HTTP_Country-Code $geoip_country_code;
proxy_pass_request_h... | NGINX | 19,751,313 | 92 |
What regular expression engine does Nginx use? There are a lot of possibilities. More to the point, what flavor of syntax does it support, that is, what syntax features can I make use of?
| Nginx uses the PCRE library. The compile-time options list has some notes on this.
| NGINX | 14,126,872 | 92 |
This is my first web-server administration experience and I want to build docker container which uses nginx as a web-server. In all docker tutorial daemon off; option is put into main .conf file but explanation about it is omitted.
I search on the internet about it and I don't understand what is the difference between ... | For normal production (on a server), use the default daemon on; directive so the Nginx server will start in the background. In this way Nginx and other services are running and talking to each other. One server runs many services.
For Docker containers (or for debugging), the daemon off; directive tells Nginx to stay i... | NGINX | 25,970,711 | 91 |
All JavaScript files are not compressed by nginx gzip.
CSS files are working.
In my nginx.conf I have the following lines:
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_buffers 16 8k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
| Change this line:
gzip_types text/plain application/x-javascript text/xml text/css;
To be this:
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
Note the addition of application/javascript and text/javascript to your list of gzip types.
There are also more... | NGINX | 23,939,722 | 91 |
I want to run a shell script every time my nginx server receives any HTTP request. Any simple ways to do this?
| You can execute a shell script via Lua code from the nginx.conf file to achieve this. You need to have the HttpLuaModule to be able to do this.
Here's an example to do this.
location /my-website {
content_by_lua_block {
os.execute("/bin/myShellScript.sh")
}
}
| NGINX | 22,891,148 | 91 |
I'm trying to test my React application on a mobile device. I'm using ngrok to make my local server available to other devices and have gotten this working with a variety of other applications. However, when I try to connect ngrok to the React dev server, I get the error:
Invalid Host Header
I believe that React bloc... | I'm encountering a similar issue and found two solutions that work as far as viewing the application directly in a browser
ngrok http 8080 --host-header="localhost:8080"
ngrok http --host-header=rewrite 8080
obviously, replace 8080 with whatever port you're running on
this solution still raises an error when I use thi... | ngrok | 45,425,721 | 370 |
From previous versions of the question, there is this: Browse website with ip address rather than localhost, which outlines pretty much what I've done so far...I've got the local IP working. Then I found ngrok, and apparently I don't need to connect via the IP.
What I am trying to do is expose my website running on... | Troubleshot this issue with ngrok. In the words of inconshrevable, some applications get angry when they see a different host header than expected.
Running the following command should fix the problem:
ngrok http [port] --host-header="localhost:[port]"
Depending on the version, you may also want to try:
ngrok http [po... | ngrok | 30,535,336 | 297 |
Is it possible to open multiples ports in ngrok in same domain?
Something like:
Fowarding http://example.ngrok.com:50001 -> 127.0.0.1:50001
Fowarding http://example.ngrok.com:50002 -> 127.0.0.1:50002
I´m working in windows and it'll be useful for debuging with IIS Express
| Yes, it is possible using multiple simultaneous tunnels, within the same hostname !
All you need to do, is to declare them on your configuration file, like this:
authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p
tunnels:
first-app:
addr: 50001
proto: http
hostname: example.ngrok.com
host_header: firs... | ngrok | 25,522,360 | 137 |
When I start an ngrok client with ./ngrok tcp 22 it runs in the foreground and I can see the randomly generated forwarding URL, such as tcp://0.tcp.ngrok.io:12345 -> localhost:22.
If I run in it the background with ./ngrok tcp &, I can't find any way to see the forwarding URL. How can I run ngrok in the background and ... | There are a couple of ways.
You can either:
1) Visit localhost:4040/status in your browser to see a bunch of information, or
2) Use curl to hit the API: localhost:4040/api/tunnels
| ngrok | 34,322,988 | 58 |
I tried running ngrok in the background with following command:
./ngrok -subdomain test -config=ngrok.cfg 80 &
the process is running:
[1] 3866
and the subdomain doesn't work.
It works with:
./ngrok -subdomain test -config=ngrok.cfg 80
Does anyone know what is going wrong here?
Thank you.
| as described previously you can run ngrok in background with
./ngrok http 8080 > /dev/null &
next you can use curl and for example jq a command-line JSON processor.
export WEBHOOK_URL="$(curl http://localhost:4040/api/tunnels | jq ".tunnels[0].public_url")"
your URL will be accessible from $WEBHOOK_URL env variable ... | ngrok | 27,162,552 | 38 |
I use mamp and I have virtual hosts all on port 8888. For example:
site1.dev:8888
site2.dev:8888
would point to localhost/site1/, localhost/site2/ etc.
Before using virtual hosts, I would just change my docroot to whatever project I was currently working on and would start ngrok like so
./ngrok http 8888 and it would... | If you prefer a free option, it is possible via:
ngrok http --host-header=site1.dev 80
| ngrok | 35,138,017 | 38 |
Is it possible to host, instead of a web app, a HTML file with NGROK? I really don't know anything about NGROK, I just used it to host a server for a Twilio app, and am wanting to use it to host a HTML file for another one of my projects. Also, anybody know how to create a HTML file on a Mac? Thanks in advance. Or, If ... | No. ngrok only tunnels traffic, so it can't actually serve the HTML file for you.
You can, however, serve a directory of files very easily. One of the quickest ways to start a server is with python. From the command line, cd to the directory containing your HTML files and run:
$ python3 -m http.server
Or for python 2:... | ngrok | 23,438,032 | 35 |
The remote Linux computer is in an internal network and has no public IP address. So I installed ngrok.
ngrok tcp 22
ngrok by @inconshreveable (Ctrl+C to quit)
Tunnel Status online
Version 2.0.19/2.0.17
Web Interface http://127.0.0.1:4040
Forwarding tcp://0.tcp.ngrok.io:364... | You are connecting to the wrong destination address. The command should be
ssh myuser@0.tcp.ngrok.io -p36428
Notice the different hostname (ie 0.tcp.ngrok.io instead of ngrok.com).
And generally you would want to put the user@hostname after all the options (eg -p36428), even though it doesn't generally cause any issu... | ngrok | 30,577,729 | 29 |
Objective: want to share a website preview using ngrok, which creates a tunnel from which my localhost can be seen with an url of something like mywebsite.ngrok.io
Problem: I use WAMP and my localhost folder looks something like this:
localhostdirectory
|-- website1
|-- website2
|-- etc
To access a website I ... | If you make do with Apache Vhost you just have to exec command
ngrok http -host-header=rewrite YOUR-LOCAL-DOMAIN:PORT
Dont forgot to edit host file for resolution @IP <-> YOUR-LOCAL-DOMAIN
| ngrok | 30,017,319 | 27 |
i have an angular app running on localhost with port 80, when i use ngrok http 80 command it shows invalid host header. how to use ngrok to work with my angular 4?
| if your local angular webapp runs at port 80, run:
ngrok http --host-header=rewrite 80
Note: ngrok should be added to your PATH
| ngrok | 44,755,464 | 23 |
I'm using ngrok to put my web application online and make some tests. But, when I reload the page, the error ERR_NGROK_702 (Too Many Connections) appears, like the image below.
Is there any way to solve or avoid it instead of buying a paid plan?
How can I decrease the inbound connection volume, as said in the message?... | You can use https://github.com/mmatczuk/go-http-tunnel it's self hosted open source ngrok alternative.
| ngrok | 40,939,587 | 20 |
I have ngrok running on a server I remote into.
I start it by using the obvious, ngrok.exe http 80. The problem is that when I sign off on that particular server, ngrok will close out and I will lose my tunnel. Is there a way I can keep the ngrok tunnel running even when I have signed off the machine? I understand if t... | As you've said If the machine is shutdown there will be no way keep the process running. There are a number of methods to do this. In each of these methods I'm assuming you already have the following config file:
config.yml
authtoken: <your-auth-token>
tunnels:
default:
proto: http
addr: 80
Ngrok L... | ngrok | 50,681,671 | 19 |
I have a Vagrant box I'm using for local development. I'm working on a webhook, which is being called from outside; so I'm thinking of using ngrok.com to proxy requests to my Vagrant environment. I'm new to this ngrok thing.
I'm trying to figure out how to access ngrok's web interface, which is normally at http://127.0... | When trying to access a site in a VM, put ngrok in the host machine, and invoke it with:
ngrok http -host-header=rewrite mydomain.com:80
You'll need to access your site (in host machine's browser) with:
http://123456.ngrok.io
But it will rewrite it to mydomain.com.
And you'll be able to access your ngrok dashboard (i... | ngrok | 33,358,414 | 18 |
I'm creating a rails app that includes devise.
I'm trying to add Twilio messaging to my site with Ngrok, i used this tutorial:
https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html
I was able to open Ngrok in the console and get the web-id they give for my url.
I keep getting this error when I plug... | Twilio developer evangelist here.
It looks like this was a problem that Rails 5 seems to have introduced. If the filter hasn't been defined by the time it is used in a controller it will raise an error. This was discovered in the Clearance project too.
Their fix was to pass the raise: false option to skip_before_filter... | ngrok | 41,266,207 | 18 |
The ASP.NET CORE application, when launched from visual studio, has the address https://localhost:44313/.
To test the performance you need to make a tunnel. I use ngrok and the command:
ngrok http -host-header=localhost 44313
But this does not work for https.
Can anyone share a working example?
|
Download the current version of ngrok
Register and get a token: https://dashboard.ngrok.com/auth
Run ngrok and set the token with the command: ngrok authtoken YOUR_AUTHTOKEN
Create a tunnel:
ngrok http --host-header=localhost https://localhost:44313
Update 11 april 2019
| ngrok | 54,800,512 | 17 |
I'm trying to integrate the Twilio API into my Rails app. The tutorial I found suggested using ngrok to put my app on the internet (rather than working on localhost). I've installed and upnzipped ngrok, and when I try to call it from the directory it is in, I get:
-bash: ngrok: command not found.
Does anyone know what... | If the binary is not located in one of the folders stored in the environment variable $PATH you have to provide at least a relative path to your current location. So if you are in the same folder as the binary then you have to call it with ./ngrok
| ngrok | 26,452,816 | 16 |
I'm used to using a Mac, and ngrok is a breeze; all you need to do is specify a port, but I'm new to IISExpress, and I can't figure out how to use ngrok and/or IIS correctly. To be clear, I've inherited a Windows machine from a coworker (who has left the company) and the set up works great locally.
The local url is sim... | So it turns out that there was nothing to change in the ApplicationHost.config file, AND I was looking at the wrong ApplicationHost.config file (the real file is normally hidden from view in C:/Windows/System32/inetsrv/Config, but you can open it in Notepad from a Command Prompt that has elevated privileges (Run as Adm... | ngrok | 29,972,875 | 15 |
[https://github.com/gtriggiano/ngrok-tunnel ] runs ngrok inside a container. Ngrok is required to run in the container to avert security risks. But am facing problems after running the scripts, which generates the url
$ docker pull gtriggiano/ngrok-tunnel
$ docker run -it -e "TARGET_HOST=localhost" -e "TARGET_PORT=3... | I have started receiving the following error with this now, so this answer may not work for you any more: Your ngrok-agent version "2.3.29" is too old. The minimum supported agent version for your account is "2.3.35". Please update to a newer version with ngrok update, by downloading from https://ngrok.com/download, or... | ngrok | 53,612,881 | 15 |
I am using the Facebook Messenger Platform to create a generic template. I am currently using ngrok to test locally, and the image_url I input for the generic template never shows in Messenger. The generic template is sent, and the image is just blank. Using Inspect, I can see that the CSS for the image is:
background-... | I have the same issue. I and the problem appears when the webhook domain is the same as the image url. If you use an image on a different server, it works.
| ngrok | 46,381,348 | 14 |
I try to work with a webhook to get a JSON,
I read that I should install ngrok because webhooks do not work locally, so I installed ngrok,
and tried to follow this small tuto : https://medium.com/@derek_dyer/rails-webhooks-local-development-7b7c755d85e3
I created my routes :
get 'invoice/webhooks'
post 'invoice/webh... | If you using rails 6 and use ngrok in development you must edit the development.rb file in config/environments for add config.hosts << "a0000000.ngrok.io" where a0000000.ngrok.io is the url supplied by ngrok without https:// , if this no work so you must add skip_before_action :verify_authenticity_token in you control... | ngrok | 59,412,490 | 12 |
I'm trying to set up an ngrok tunnel to a locally run webserver serving on port 5000. I can access the website fine over localhost:5000, but when I set up an ngrok tunnel on port 5000 I get net::ERR_CONTENT_LENGTH_MISMATCH errors on all of the css and js resources in Chrome 46.0 and Safari 9.0.1.
I do not get these er... | I've resolved this issue just with adding lines bellow in devServer config. So I've changed default express timeout, turned on compression and added proxy. Maybe this will help someone...
keepAliveTimeout: 120000 * 5,
compress: true,
// Set this if you want to enable gzip compression for assets
proxy: {
'**': 'http:/... | ngrok | 33,659,218 | 11 |
ngrok's awesome web interface is pointed to http://127.0.0.1:4040 by default. I have other applications listening on that port, however, and need to change it so that ngrok listens on, say, http://127.0.0.1:4045.
| Create a config.yml wherever ngrok is looking for its default config on your platform. If the directory doesn't exist, make it (on windows this is done by entering .ngrok2. as the folder name).
OS X /Users/example/.ngrok2/ngrok.yml
Linux /home/example/.ngrok2/ngrok.yml
Windows C:\Users\example\.ngrok2\ngrok.yml... | ngrok | 36,018,375 | 11 |
I have been using ngrok with ASP.NET 4.X without encountering any problems.
Unfortunately, when I try to forward app build in ASP.NET Core 2 I run into a problem that I can't solve.
I tried following combinations of commands to start ngrok:
ngrok http 44374-host-header="localhost:44374"
ngrok http -host-header=rewrite... | I solved my problem.
properties/launchSettings.json content:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59889/",
"sslPort": 44374
}
},
"profiles": {
"IIS Express": {
"commandName": "I... | ngrok | 49,134,294 | 11 |
I'm trying to begin developing a skill for alexa using flask-ask and ngrok in python. Following is my code:
from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/reddit_reader")
def get_headlines(... | Ran into the same issue, you can fix it by downgrading cryptography to anything less than 2.2 for me.
pip install 'cryptography<2.2'
rpg711 gets all the credit (see comments the on original post)
| ngrok | 49,375,054 | 11 |
I have a MongoDb hosted locally in my machine and runs successfully in port localhost:27017. The database has a user name and password with a collection named, "testDb". In the code, I am able to access the database successfully using localhost.
I am trying to access this MongoDb from a remote desktop using ngrok. I ha... | MongoDB uses TCP not HTTP.
Try following command :
ngrok tcp 27017
(note the tcp, not http which I think is what you used)
There are a couple of extra steps you need to do for some reason when you use TCP, and ngrok will prompt you and tell you what you need to do when you try the above command.
Sign up for an n... | ngrok | 57,220,540 | 10 |
I'm using Docker I have implemented a system to deploy environments (on a single server) based on Git branches using Traefik (*.dev.domain.com) and Docker Compose templates.
I like Kubernetes and I've never switched to it since I'm limited to one single server for my infrastructure. I've only used it using local instal... | AFAIU,
I do not see a requirement for kubernetes unless we are doing below at least for single host using native docker run or docker-compose or docker engine swarm mode -
Make sure there are enough(>=2) replicas of your app in a single server and you are balancing the load across those apps docker containers.
I... | Traefik | 52,800,958 | 28 |
I meet some problems using traefik with docker and I don't know why.
With some containers, it's works like a charm and for other ones, I have an error when I try to access to these ones : Bad gateway (error 502).
Here is my traefik.toml :
# Service logs (here debug mode)
debug = true
logLevel = "DEBUG"
defaultEntryPoi... | The traefik port should be the http port of the container, not the published port on the host. It communicates over the docker network, so publishing the port is unnecessary and against the goals of only having a single port published with a reverse proxy to access all the containers.
In short, you need:
traefik.port=8... | Traefik | 49,417,889 | 27 |
First of all I'm sorry if I'm not using the right terms to ask this question, but I'm not up to the terminology in place.
I have traefik running in a docker container and serving some services with the PathPrefix option, for instance, www.myserver.com/wordpress redirects to a docker container running wordpress.
But how... | With the new Traefik (v.2) you need to use a combination of labels and an external file, you can find below my working example.
In your docker compose you need to add the comands to define the external file and enable the provider
- "--providers.file=true"
- "--providers.file.filename=/etc/traefik/rules.toml"
Int... | Traefik | 46,245,684 | 26 |
I'd like to serve static ressources such as images, js bundles, html pages... with Traefik like I was able to do with nginx
# nginx config
server {
root /www/data;
location ~ \.js {
root /www/bundles;
}
}
Many thanks
Cheers
| Traefik doesn't serve static files (it's a not a web server it's a reverse proxy/load balancer).
You must use a container, which contains a web server with your files.
| Traefik | 46,503,797 | 23 |
I have a problem with setting up mailcow with traefik, I encounter gateway timeouts. I also have this problem with nextcloud, so I would be really interested, what causes these issues with gateway timeout.
I guess it has to do with port 9000 and php-fpm upstream or sth.
But I want to know for sure, and how to deal wi... | I think I may have had a similar issue to what you are/were experiencing. Take a look at this GitHub issue: https://github.com/containous/traefik/issues/979
If your problem is the same as mine, here is the issue:
Traefik is on a "front facing" network, so is one of your services, but that service is also part of a "bac... | Traefik | 46,161,017 | 21 |
I'm currently trying to get traefik to use multiple routers and services on a single container, which isn't working and i don't know if this is intended at all.
Why?
Specificly i'm using an gitlab omnibus container and wanted to use / access multiple services inside the omnibus container since gitlab is providing not o... | I found the solution to my Question.
There's indeed a little bit i missed:
traefik.http.routers.myRouter.service=myService
With this Label i can point a Router to a specific Service and should be able to add multiple services to one container:
labels:
- "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
... | Traefik | 59,856,722 | 21 |
I've got some strange issue. I have following setup:
one docker-host running traefik as LB serving multiple sites. sites are most php/apache. HTTPS is managed by traefik.
Each site is started using a docker-compose YAML containing the following:
version: '2.3'
services:
redis:
image: redis:alpine
container_na... | Another reason can be that you might be accidentally mapping to the vm's port instead of the container port.
I made a change to my port mapping on the docker-compose file and forgot to update the labeled port so it was trying to map to a port on the machine that was not having any process attached to it
Wrong way:
port... | Traefik | 49,406,737 | 18 |
I cannot figure out how to get a simple service to be accessible by both http and https on localhost. This is my setup so far and I'm using traefik V2.xxx.
I want to be able to hit this site using both https/http protocols (for reasons on dev machines only). The https works just fine but http does NOT. What labels do I... | Finally got this working. The traefik docs are squarely in the esoteric region on certain topics and given the recent major 2.0 release there isn't a lot of examples out there yet.
Here is my working docker-compose.yml file where the application is now being exposed using the same host "whomai.localhost" and on both po... | Traefik | 59,830,648 | 18 |
Motivations
I am a running into an issue when trying to proxy PostgreSQL with Traefik over SSL using Let's Encrypt.
I did some research but it is not well documented and I would like to confirm my observations and leave a record to everyone who faces this situation.
Configuration
I use latest versions of PostgreSQL v12... | SNI routing for postgres with STARTTLS has been added to Traefik in this PR. Now Treafik will listen to the initial bytes sent by postgres and if its going to initiate a TLS handshake (Note that postgres TLS requests are created as non-TLS first and then upgraded to TLS requests), Treafik will handle the handshake and ... | Traefik | 63,354,909 | 18 |
So I'm trying to set up a gitlab-ce instance on docker swarm using traefik as reverse proxy.
This is my proxy stack;
version: '3'
services:
traefik:
image: traefik:alpine
command: --entryPoints="Name:http Address::80 Redirect.EntryPoint:https" --entryPoints="Name:https Address::443 TLS" --defaultentrypoints=... | Turns out all I had to do was set the traefik label, traefik.docker.network to traefik-net, see https://github.com/containous/traefik/issues/1254
| Traefik | 46,698,425 | 16 |
According to the Traefik 1.7 documentation you should be able to have Traefik perform a 302 redirect using:
traefik.ingress.kubernetes.io/redirect-regex
traefik.ingress.kubernetes.io/redirect-replacement
My goal is to simply remove the www. from the address.
This is what I've tried, but I get a 404 service not found.... | I was having the same issue and ended up making it work with:
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: www-redirect
namespace: public
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/preserve-host: "true"
traefik.ingress.kubernetes.io/redirect-per... | Traefik | 48,627,768 | 16 |
I'm interested in setting up fail2ban with my Traefik deployment. I found a gist that has some snippets in it, but I'm not clear on how to use them. Can anyone fill in the blanks please? Or, is there a better way to implement fail2ban style security with Traefik?
| I was able to accomplish this starting with the gist you posted. This is under the assumptions you have Traefik already working, want to block IPs that have HTTP Basic Auth failures, and ban them with iptables. There's a couple of pieces so let me start with the container configurations:
Traefik docker-compose.yaml
ver... | Traefik | 52,123,355 | 16 |
Do you happen to know where the Traefik logs are located? I read the documentation on Traefik and it says it will output to stdout but when I start the docker container with docker-compose up -d it doesn't show anything in stdout after I try the domain name and pull up multiple linked docker containers.
I also tried to... | To see logs in the stdout event if you run docker-compose up -d:
docker-compose logs -f
https://docs.docker.com/compose/reference/logs/
FYI The path ./traefik.log is inside the Traefik container.
[traefikLog]
filePath = "./traefik.log"
With your files (without the section [traefikLog]), I see the logs.
However, y... | Traefik | 54,776,024 | 16 |
I did search the manual but really couldn't make it very clear, even using the keywords to google that.
I need to proxy the /_ to the API container, some rule like that www.mydomain.com/_ => API container
There is already a specified domain point to this API container
api.mydomain.com => API container
This is my docker... | You can use segment labels:
version: '3.3'
services:
testapi:
image: git.xxxx.com/api/core/test:latest
restart: always
networks:
- web
- default
expose:
- "80"
labels:
- "traefik.enable=true"
- "traefik.port=80"
- "traefik.docker.network=web"
#this domain is used for ... | Traefik | 52,240,784 | 15 |
I am trying to use Traefik to deploy proxy multiple applications in my Docker Swarm mode cluster.
I have got it so that it proxies a named Host but I want it to proxy on a named Host and Path, but I cannot work out the labels I need to use.
This is the docker service command I am using:
docker service create \
... | Traefik v1
If you want multiple rules to apply in order for a routing decision to become effective, separate them by semicolon. For instance:
Host: <your host rule>; PathPrefixStrip: /portainer
What the above means is: If the host and path prefix match, Traefik will route requests to the associated backend(s) (and str... | Traefik | 44,232,354 | 14 |
I want Ingress to redirect a specific subdomain to one backend and all others to other backend. Basically, I want to define a rule something like the following:
If subdomain is foo.bar.com then go to s1, for all other subdomains go to s2
When I define the rules as shown below in the Ingress spec, I get this exception... | This is now possible in Kubernetes with nginx:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: nginx
kubernetes.io/ingress.global-static-ip-name: web-static-ip
nginx.ingress.kubernetes.io/rewrite-target: /$1
... | Traefik | 52,328,483 | 14 |
Currently I'm trying set up a loadbalancer/reverse proxy with Traefik for some docker containers. I'm having trouble with configuring Treafik to make my apps available using a some prefix paths. I'm able to get a basic Traefik configuration running using Docker and Docker compose, based on this example. The problem is ... | This morning I found the solution. The correct approach in cases like these should be to use the PathPrefixStrip rule. However, as mentioned here, putting a / at the end of the rule will break the setup. I created a working configuration by removing / at the end of the PathPrefixStrip: /portainer4/ rule. So this docker... | Traefik | 41,637,806 | 13 |
How do I enable log rotation for log files e.g. access.log.
Is this built in ?
Docs only say "This allows the logs to be rotated and processed by an external program, such as logrotate"
| If you are running Traefik in a Docker container then you can do something like this:
Check that logrotate is installed on the Docker host:
logrotate --version
Create file in /etc/logrotate.d/:
vi /etc/logrotate.d/traefik
Put the following script, do not forget to fill with the container name.
/var/log/traefik/*.log ... | Traefik | 49,450,422 | 13 |
I am trying to configure Basic Authentication on a Nginx example with Traefik as Ingress controller.
I just create the secret "mypasswd" on the Kubernetes secrets.
This is the Ingress I am using:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginxingress
annotations:
ingress.kubernetes.io/auth-ty... | It is popular to use basic authentication. In reference to Kubernetes documentation, you should be able to protect access to Traefik using the following steps :
Create authentication file using htpasswd tool. You'll be asked for a password for the user:
htpasswd -c ./auth
Now use kubectl to create a secret in ... | Traefik | 50,130,797 | 13 |
I have read the documentation but I can not figure out how to configure Traefik v2 to replace Nginx as a reverse proxy for web sites (virtual hosts) without involving Docker. Ideally there would be let'sencrypt https as well.
I have a service running at http://127.0.0.1:4000 which I would like to reverse proxy to from ... | I figured it out,
the first part to note is that in traefik v2 there are two types of configuration, static and dynamic. So I created two files, traefik.toml and traefik-dynamic.toml.
contents of traefik.toml:
[log]
level = "DEBUG"
filePath = "log-file.log"
[accessLog]
filePath = "log-access.log"
buf... | Traefik | 58,496,270 | 13 |
I have the problem that I can route HTTPS traffic but I can not globally redirect the HTTP traffic to HTTPS. In my case I only want HTTPS traffic, so that I want to redirect all the incoming traffic.
Currently I get an 404 error while I try to serve my URLs over HTTP.
I already enabled DEBUG logs in Treafik, but I can ... | You don't need to configure the Traefik service itself. On Traefik you only need to have entrypoints to :443 (websecure) and :80 (web)
Because Traefik only acts as entryPoint and will not do the redirect, the middleware on the target service will do that.
Now configure your target service as the following:
version: '2'... | Traefik | 58,666,711 | 12 |
I'm trying to set up Upsource to work behind Traefik: https://www.jetbrains.com/help/upsource/proxy-configuration.html
traefik is listening to port 8008 and 8443 (since 80/443 will be used for another):
--entryPoints='Name:http Address::8008 Redirect.EntryPoint:https' --entryPoints='Name:https Address::8443 TLS'
docke... | Traefik handle websocket, and you don't need any specific configuration for this.
Your problem seems to be more about the challenge in Let's Encrypt.
Let's Encrypt doesn't handle TLS Challenge on other port than the default one and the default challenging in Traefik is TLS :(
So you need to configure Traefik to use DNS... | Traefik | 46,313,356 | 11 |
Hello I tried looking at the auth options in the annotations for kubernetes traefik ingress. I couldn't find anything where I could configure Forward Authentication as documented here: https://docs.traefik.io/configuration/entrypoints/#forward-authentication
I would like to be able to configure forward authentication p... | According to the Traefik documentation that feature will be available in version 1.7 of Traefik (currently a release candidate).
Here is a link to the authentication documentation
My guess is that you will need to add the following 2 annotations:
ingress.kubernetes.io/auth-type: forward
ingress.kubernetes.io/auth-url: ... | Traefik | 50,964,605 | 11 |
I'm looking for a recommended configuration for SSL/TLS in Traefik. I have set minVersion = "VersionTLS12" to avoid the weaker older versions and found the supported ciphers in Go. Cross-checking that with the recommendations from SSLLabs I came up with the following sequence (order matters):
cipherSuites = [
"TLS_EC... | You can use this page to generate your traefik config: https://ssl-config.mozilla.org/#server=traefik&server-version=1.7.12&config=intermediate
# generated 2019-07-17, https://ssl-config.mozilla.org/#server=traefik&server-version=1.7.12&config=intermediate
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryP... | Traefik | 52,128,979 | 11 |
I try in a simple way to access traefik via the sub-domain traefik (traefik.DOMAIN.com). As soon as I gain access to it, the SSL Certificate is well functional but impossible to access the dashboard (404 error)
docker-compose.yml
version: '3'
services:
reverse-proxy:
image: traefik:v2.2
container_name: traef... | After reading the documentation and checking the logs in DEBUG mode I was able to make it work. The key here is the trailing / which is mandatory.
traefik.toml
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirec... | Traefik | 63,116,661 | 11 |
My goal is to protect the traefik front-end with basic authentication.
I am running Traefik version v1.4.3 built on 2017-11-14_11:14:24AM in a Docker container.
My docker-compose.yml file looks like this:
version: "3"
services:
proxy:
image: traefik
command: --web --docker --docker.domain=docker.localhost --... | The reason why the setup shown in my own question was not working, was the 'command' entry in my docker-compose.yml file:
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
This command overwrite the [web] and [docker] settings form my traefik.toml file.
So in case when you start traefik as a d... | Traefik | 47,382,756 | 10 |
I am configuring Traefik to work as a reverse proxy in my development environment. I currently have applications running on different ports, and different PATHs.
My Environment:
Traefik is running on a Host (192.168.0.10). Listening on port 80, 443 and 8080 (traefik dashboard).
My applications are running on a differen... | You need to add this parameter in the frontends "AddPrefix:/myprefix" and remove path in backends URL like this:
(url="http://192.168.0.11:8200/myprefix") to (url="http://192.168.0.11:8200)
You just need move this "path" to "AddPrefix" param in frontends configurations if you have PATH in your URL.
All the other confi... | Traefik | 52,083,071 | 10 |
Yes,
I get this when I try to run traefik with https. Problem is I mount the dir on my Win7 machine but I cant chmod the file.
The mount is working but file permissions are off.
looks like this:
volumes
- d:/docker/traefikcompose/acme/acme.json:/etc/traefik/acme/acme.json:rw
traefik | time="2018-09-04T12:57:11Z... | I did finally find the solution thanks to Cooshals kind help,
we have to ssh into the virtualbox-machine and make the file there, and then point it out right from the docker-compose.yml, in this case I did like this:
docker-machine ssh default
touch /var/acme.json
chmod 600 /var/acme.json
Then in my docker-compose:
vo... | Traefik | 52,167,035 | 10 |
So I am using the helm chart stable/traefik to deploy a reverse proxy to my cluster. I need to customise it beyond what is possible with the variables I can set for the template.
I want to enable the dashboard service while not creating an ingress for it (I set up OpenVPN to access the traefik dashboard only via VPN).
... | You don't necessarily have to push to your own repository as you could take the source code and include the chart in your own as source. For example, if you dig into the gitlab chart in their charts dependencies they've included multiple other charts as source their, not packaged .tgz files. That enables you to make ch... | Traefik | 53,172,597 | 10 |
Recently I am moving a project to Kubernetes and have used Traefik as the ingress controller. For Traefik I have used the Traefik Kubernetes Ingress provider for routing. When I tried to add the Traefik dashboard, I found that seems it can only be added using IngressRoute (ie. using Kubernetes CRD as provider).
I have ... | So I have solved the Traefik Dashboard problem using Traefik Kubernetes Ingress only, the answer to the first question is 'Yes':
The following is my configuration:
traefik-deployment.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: traefik
namespace: ingress-traefik
labels:
app: traefik
spec:
repl... | Traefik | 64,582,491 | 10 |
I'm new to the docker. Any help and tips are welcome.
Environments:
Windows: Windows 10 Pro 21H1
Docker Desktop: 3.4
I can run hello work example without any issues. But seems like I can't use named piped, can't figure out what is the issue.
Some people mentioned named piped is only available for Windows server, but ... | This error occurs when using Docker Compose V2. Turn off the option in Docker Desktop settings or use the CLI command docker-compose disable-v2.
| Traefik | 68,010,612 | 10 |
In order to deal with the microservice architecture, it's often used alongside a Reverse Proxy (such as nginx or apache httpd) and for cross cutting concerns implementation API gateway pattern is used. Sometimes Reverse proxy does the work of API gateway.
It will be good to see clear differences between these two appr... | It is easier to think about them if you realize they aren't mutually exclusive. Think of an API gateway as a specific type reverse proxy implementation.
In regards to your questions, it is not uncommon to see both used in conjunction where the API gateway is treated as an application tier that sits behind a reverse pro... | Tyk | 35,756,663 | 173 |
I've created several RESTful microservices and dockerized them. Now I want to have a web-based UI for them and the ability to create users and grant permissions to them to use some of the APIs.
I know that I need some kind of API gateway. My first thought was that I always could do that bruteforce way: create some djan... | I was looking for something similar, including support for rate limiting, UI console, etc. It boils down to a few freemium tools like:
apigee
mashape
apiary
3scale.net
and a few open source ones:
tyk
kong
ApiAxle
WSO2
API Umbrella
I've decided on tyk since it has a nice UI console and solid docs. All of them were m... | Tyk | 31,546,631 | 11 |
I'm trying to save a UIImage to NSData and then read the NSData back to a new UIImage in Swift. To convert the UIImage to NSData I'm using the following code:
let imageData: NSData = UIImagePNGRepresentation(myImage)
How do I convert imageData (i.e., NSData) back to a new UIImage?
| UIImage(data:imageData,scale:1.0) presuming the image's scale is 1.
In swift 4.2, use below code for get Data().
image.pngData()
| Swift | 32,297,704 | 172 |
I would like to know if there is currently (at the time of asking, the first Xcode 12.0 Beta) a way to initialize a @StateObject with a parameter coming from an initializer.
To be more specific, this snippet of code works fine:
struct MyView: View {
@StateObject var myObject = MyObject(id: 1)
}
But this does not:
st... | Here is a demo of solution. Tested with Xcode 12+.
class MyObject: ObservableObject {
@Published var id: Int
init(id: Int) {
self.id = id
}
}
struct MyView: View {
@StateObject private var object: MyObject
init(id: Int = 1) {
_object = StateObject(wrappedValue: MyObject(id: id))
... | Swift | 62,635,914 | 171 |
Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear function were executed.
Now iOS 13 will present view controllers as a sheet as default, which means the card will partially cover the underlying view controller, which means that view... |
Is there a way to detect that the presented view controller sheet was dismissed?
Yes.
Some other function I can override in the parent view controller rather than using some sort of delegate?
No. "Some sort of delegate" is how you do it. Make yourself the presentation controller's delegate and override presentation... | Swift | 56,568,967 | 171 |
I want to convert a string to Base64. I found answers in several places, but it does not work anymore in Swift. I am using Xcode 6.2. I believe the answer might be work in previous Xcode versions and not Xcode 6.2.
Could someone please guide me to do this in Xcode 6.2?
The answer I found was this, but it does not work ... | Swift
import Foundation
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}... | Swift | 29,365,145 | 171 |
I'm unwrapping two values from a dictionary and before using them I have to cast them and test for the right type. This is what I came up with:
var latitude : AnyObject! = imageDictionary["latitude"]
var longitude : AnyObject! = imageDictionary["longitude"]
if let latitudeDouble = latitude as? Double {
if let long... | Update for Swift 3:
The following will work in Swift 3:
if let latitudeDouble = latitude as? Double, let longitudeDouble = longitude as? Double {
// latitudeDouble and longitudeDouble are non-optional in here
}
Just be sure to remember that if one of the attempted optional bindings fail, the code inside the if-let... | Swift | 24,592,004 | 171 |
I'm implementing socket.io in my swift ios app.
Currently on several panels I'm listening to the server and wait for incoming messages. I'm doing so by calling the getChatMessage function in each panel:
func getChatMessage(){
SocketIOManager.sharedInstance.getChatMessage { (messageInfo) -> Void in
dispatch... | Swift 2.0
Pass info using userInfo which is an optional Dictionary of type [NSObject : AnyObject]?
let imageDataDict:[String: UIImage] = ["image": image]
// post a notification
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notificationName"), object: nil, userInfo: imageDataDict)
// `default` i... | Swift | 36,910,965 | 170 |
This is my case:
let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText("wrong_password") //here is an error
UI Testing Failure - Neither element nor any descendant has keyboard focus. Element:
What is wrong? This is working nice for normal textF... | This issue caused me a world of pain, but I've managed to figure out a proper solution. In the Simulator, make sure I/O -> Keyboard -> Connect hardware keyboard is off.
| Swift | 32,184,837 | 170 |
What is wrong with my code for getting the filenames in the document folder?
func listFilesFromDocumentsFolder() -> [NSString]?{
var theError = NSErrorPointer()
let dirs = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true) as? [String]
i... | Swift 5
do {
// Get the document directory url
let documentDirectory = try FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
)
print("documentDirectory", documentDirectory.path)
// Get the directory contents urls ... | Swift | 27,721,418 | 170 |
I have a generic function that calls a web service and serialize the JSON response back to an object.
class func invokeService<T>(service: String, withParams params: Dictionary<String, String>, returningClass: AnyClass, completionHandler handler: ((T) -> ())) {
/* Construct the URL, call the service and pa... | You are approaching it in the wrong way: in Swift, unlike Objective-C, classes have specific types and even have an inheritance hierarchy (that is, if class B inherits from A, then B.Type also inherits from A.Type):
class A {}
class B: A {}
class C {}
// B inherits from A
let object: A = B()
// B.Type also inherits f... | Swift | 24,308,975 | 170 |
How to check if a file exists in the Documents directory in Swift?
I am using [ .writeFilePath ] method to save an image into the Documents directory and I want to load it every time the app is launched. But I have a default image if there is no saved image.
But I just cant get my head around how to use the [ func file... | Swift 4.x version
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let url = NSURL(fileURLWithPath: path)
if let pathComponent = url.appendingPathComponent("nameOfFileHere") {
let filePath = pathComponent.path
let fileManager = FileManage... | Swift | 24,181,699 | 170 |
I am making a CheckList application with a UITableView. I was wondering how to add a swipe to delete a UITableViewCell.
This is my ViewController.swift:
import UIKit
class ViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource {
var tableView: UITableView!
var textFiel... | Add these two functions:
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewC... | Swift | 24,103,069 | 169 |
I'm currently using Xcode 11 Beta 5. Within my application, it runs fine on iOS 12 and under. However, on iOS 13 it looks like it's using the UIScene by default. This is causing my app to not do anything.
When the app launches on fresh install, there is a terms and conditions the user must accept. After agreeing they g... | While you should embrace using scenes when your app is run under iOS 13 and later, you can fully opt out while you still support iOS 12 or earlier.
Completely remove the “Application Scene Manifest” entry from Info.plist.
If there is a scene delegate class, remove it.
If there are any scene related methods in your a... | Swift | 57,467,003 | 168 |
I want to sort a dictionary in Swift. I have a dictionary like:
"A" => Array[]
"Z" => Array[]
"D" => Array[]
etc. I want it to be like
"A" => Array[]
"D" => Array[]
"Z" => Array[]
etc.
I have tried many solutions on SO but no one worked for me. I am using XCode6 Beta 5 and on it some are giving compiler error and so... | let dictionary = [
"A" : [1, 2],
"Z" : [3, 4],
"D" : [5, 6]
]
let sortedKeys = Array(dictionary.keys).sorted(<) // ["A", "D", "Z"]
EDIT:
The sorted array from the above code contains keys only, while values have to be retrieved from the original dictionary. However, 'Dictionary' is also a 'CollectionType'... | Swift | 25,377,177 | 168 |
What is the purpose of using IBOutlets and IBActions in Xcode and Interface Builder?
Does it make any difference if I don't use IBOutlets and IBActions?
Swift:
@IBOutlet weak var textField: UITextField!
@IBAction func buttonPressed(_ sender: Any) { /* ... */ }
Objective-C:
@property (nonatomic, weak) IBOutlet UIText... | IBAction and IBOutlet are macros defined to denote variables and methods that can be referred to in Interface Builder.
IBAction resolves to void and IBOutlet resolves to nothing, but they signify to Xcode and Interface builder that these variables and methods can be used in Interface builder to link UI elements to your... | Swift | 1,643,007 | 168 |
How to remove the left and right Padding of a List in SwiftUI?
Every List i create has borders to the leading and trailing of a cell.
What modifier should I add to remove this?
| It looks like .listRowInsets doesn't work for rows in a List that is initialised with content.
So this doesn't work:
List(items) { item in
ItemRow(item: item)
.listRowInsets(EdgeInsets())
}
But this does:
List {
ForEach(items) { item in
ItemRow(item: item)
.listRowInsets(EdgeInsets(... | Swift | 56,614,080 | 167 |
openURL has been deprecated in Swift 3.
Can anyone provide some examples of how the replacement openURL:options:completionHandler: works when trying to open a url?
| All you need is:
guard let url = URL(string: "http://www.google.com") else {
return //be safe
}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
| Swift | 39,546,856 | 167 |
How can I do something like this? Take the first n elements from an array:
newNumbers = numbers[0..n]
Currently getting the following error:
error: could not find an overload for 'subscript' that accepts the supplied arguments
EDIT:
Here is the function that I'm working in.
func aFunction(numbers: Array<Int>, positio... | This works for me:
var test = [1, 2, 3]
var n = 2
var test2 = test[0..<n]
Your issue could be with how you're declaring your array to begin with.
EDIT:
To fix your function, you have to cast your Slice to an array:
func aFunction(numbers: Array<Int>, position: Int) -> Array<Int> {
var newNumbers = Array(numbers[0.... | Swift | 24,034,398 | 167 |
Rather than creating two UIImageViews, it seems logical to simply change the image of one view. If I do that, is there anyway of having a fade/cross dissolve between the two images rather than an instant switch?
| It can be much simpler using the new block-based, UIKit animation methods.
Suppose the following code is in the view controller, and the UIImageView you want to cross-dissolve is a subview of self.view addressable via the property self.imageView Then all you need is:
UIImage * toImage = [UIImage imageNamed:@"myname.png... | Swift | 7,638,831 | 167 |
I am doing a login page. I have UITextField for password.
Obviously, I do not want the password to be seen; instead, I want circles to show when typing.
How do you set the field for this to happen?
| Please set your UItextField property secure..
Try this..
textFieldSecure.secureTextEntry = true
textFieldSecure is your UITextField...
For newer Swift version, it is textFieldSecure.isSecureTextEntry = true
| Swift | 6,578,824 | 167 |
When I set firstThing to default nil this will work, without the default value of nil I get a error that there is a missing parameter when calling the function.
By typing Int? I thought it made it optional with a default value of nil, am I right? And if so, why doesn't it work without the = nil?
func test(firstThing: I... | Optionals and default parameters are two different things.
An Optional is a variable that can be nil, that's it.
Default parameters use a default value when you omit that parameter, this default value is specified like this: func test(param: Int = 0)
If you specify a parameter that is an optional, you have to provide i... | Swift | 37,305,951 | 166 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.