Simply formats your NGINX Configurations
- Open a Document
- Make sure the File Association is set to NGINX
- Press Strg + Alt + F or select 'Format Document' from the command selection
- Your NGINX Configuration should be formatted properly
A simple Formatter, which formats NGINX Configuration Files in VSCode
Home Page: https://marketplace.visualstudio.com/items?itemName=raynigon.nginx-formatter
License: MIT License
Simply formats your NGINX Configurations
Example:
worker_processes 5;
worker_rlimit_nofile 8192;
events {
worker_connections 4096;
}
http {
client_max_body_size 10m;
server {
listen 8443 default_server ssl http2 reuseport;
ssl_certificate /certs/certificate.crt;
ssl_certificate_key /certs/privateKey.key;
server_name _;
keepalive_timeout 620s;
location / {
root /data/;
index index.html;
}
}
}
worker_processes 5;
worker_rlimit_nofile 8192;
events {
worker_connections 4096;
}
http {
client_max_body_size 10m;
server {
listen 8443 default_server ssl http2 reuseport;
ssl_certificate /certs/certificate.crt;
ssl_certificate_key /certs/privateKey.key;
server_name _;
keepalive_timeout 620s;
location / {
root /data/;
index index.html;
}
}
}
nginx.conf
Instead of using the dead https://github.com/shanoor/vscode-nginx switch instead to https://github.com/william-voyek/vscode-nginx
I've observed the following bug. I'm not sure if it's a vscode-nginx-formatter issue or nginxbeautifier issue, but I'm guessing it's a vscode-nginx-formatter issue because the next text seems dependent on where the cursor is placed.
events {}
The config contains the same tokens with perhaps a different whitespace between them.
There are a different number of tokens depending on whether the cursor is placed.
when i format this:
location ~ ^/\d{3}/ {
try_files $uri /index.html;
}
the result is error:
location ~ ^/\d;
thanks!
and,the version is 0.0.4
How to set more association files?
http://joxi.ru/krDKXGaFgZJkyA
When i try to buatify http.conf - nothing happening...
The purpose of using a formatter is to bring clarity, but this extension brings max confusion!
the following sample code will produce the result shown in the picture:
# regex formatting in both, map and location are full of bugs, I give 2 examples but the list can be loooong!
location ~* (?:#.*#|\.(?:bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|^~.*)$ {
deny all;
}
map $http_name $http_value {
~*^(www\.)?domain\.com:.* 1;
default 0;
}
map $http_name $http_value {
7d789ac019786442253db411b8e77632 1; # value not recognized as a number
ee2f1840417818a254ae94256b0eb8f3 22; # key not recognized as hex number
3kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 33; # key wrongfully recognized as number
default 44;
}
server {
location / {
# wrong format for names as directives despite the fact that they are not in the first position
include includes/location/dummy/map/dummy/geo/dummy/server/dummy/if/dummy/break/so.on
# directives not recognized
rewrite ^/api/(.*)$ /$1 break;
}
}
I find out https://nginxbeautifier.com/ formats better than https://github.com/tmont/nginx-conf.
Would you like to look at it!
Thank you!
when here is line like
/build${mobile_path}/
it replaces it witj
/build$
Hey there,
I'm using nginx in a docker container with the official image.
My nginx.conf
contains environment variables definitions that gets interpolated when nginx starts
server {
listen 80;
listen [::]:80;
server_name www.${DOMAIN_NAME};
return 301 $scheme://${DOMAIN_NAME}$request_uri;
}
I i use the formatter, it gets formatted to
server {
listen 80;
listen [::]:80;
server_name www.$ {
DOMAIN_NAM
}
;
return 301 $scheme://$ {
DOMAIN_NAM
}
$request_uri;
}
Didn't have a chance to look at the code for now, so no idea what's going on ๐ค
Here's an example of valid nginx.conf.
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
log_format json_combined escape=json
'{'
'"timeLocal":"$time_local",'
'"remoteAddr":"$remote_addr",'
'"forwarderFor":"$http_x_forwarded_for",'
'"remoteUser":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"bytesSent":"$bytes_sent",'
'"requestTime":"$request_time",'
'"httpReferrer":"$http_referer",'
'"gzipRatio":"$gzip_ratio",'
'"httpUserAgent":"$http_user_agent"'
'}';
tcp_nopush on;
tcp_nodelay on;
}
Formatter breaks it this way:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
log_format json_combined escape=json
' {
'
'"timeLocal":"$time_local",'
'"remoteAddr":"$remote_addr",'
'"forwarderFor":"$http_x_forwarded_for",'
'"remoteUser":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"bytesSent":"$bytes_sent",'
'"requestTime":"$request_time",'
'"httpReferrer":"$http_referer",'
'"gzipRatio":"$gzip_ratio",'
'"httpUserAgent":"$http_user_agent"'
}
';
tcp_nopush on;
tcp_nodelay on;
}
Probably it was caused by some new changes, cause ~ 1 year ago it was working fine with such file.
Looks like nginxbeautifier bug.
VSCODE Version: 1.49.1
nginx-formatter Version: v0.0.10
nginx.conf hint Version: v0.1.0
I installed nginx-formatter and nginx.conf prompt together in vscode, and opened the nginx.conf file. There are NGINX and NGINX Conf in language mode. It can be formatted in NGINX mode, but the syntax cannot be highlighted. In NGINX Conf mode, the related functions prompted by nginx.conf can be used normally, but the file format cannot be executed. Please solve this problem.
this is what I get running this formatter:
server {
if ($host = www.foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = xxx.foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name foo.bar www.foo.bar xxx.foo.bar;
listen 80;
return 404; # managed by Certbot
}
this is what I would expect instead:
server {
if ($host = www.foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = xxx.foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = foo.bar) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name foo.bar www.foo.bar xxx.foo.bar;
listen 80;
return 404; # managed by Certbot
}
Is this intendet?
Hi,
I'd like to have a nginx formatter but without loosing a great syntax highlighting.
I use hangxingliu.vscode-nginx-conf-hint
for syntax highlighting and it's perfect, but it cannot work with your formatter...
Is it possible to for you to use this one instead of william-voyek.vscode-nginx
which is not a great syntax highlighting ?
And also hangxingliu.vscode-nginx-conf-hint
provides hints as you type.
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.