Articles of nginx

重写模块适合代理来自nginx的不同expressjs路由吗?

我有一个运行在docker容器中的expressjs节点服务器。 对于这个例子,它只有一个路由:GET /user返回一个简单的JSON对象。 我也有一个nginx服务器代理这个快递服务器使用: location /api { rewrite ^/api/(.*) /$1 break; proxy_pass http://nodeapp:3000/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for; } 在我的index.js我使用url /api/user创build了一个XMLHttpRequest。 是重写模块, rewrite ^/api/(.*) /$1 break; ,在我的快递应用程序中代理路线的有效解决scheme? 还有其他的select吗? 虽然这工作的东西似乎“closures”,我不得不使用正则expression式这样的事情。 我不做devops的工作,只能玩弄nginx,所以如果有更好的解决scheme,我将不胜感激,如果你能指出我在正确的方向。

代理wss通过nginx(连接重置由对等)

我有浏览器和服务器上的IP地址abcd现在我有2个可能的URL到服务器: 通过浏览器通过Nginx browser -> https://abcd/ -> server 通过从WSS的WSS browser -> wss://abcd:10062 -> server 所以,443(nginx)上的服务器listnes和10062上的一些其他应用程序。我想要更改第二个连接到同一个端口(443): browser -> wss://abcd/someurl -> server 那么是否有可能在nginx中代理abcd:10062,如下所示: server { listen 80; listen 443 ssl; ssl_certificate /path/to/crt/for/https; ssl_certificate_key /path/to/key/for/https; server_name abcd; location /someurl { –>> What to write here to create redirect for wss://abcd:10062 ? << — } # the other locations here […]

如何将头文件传递给Nginx的远程error handling程序

我有nginx服务器发送404错误到1.1.1.1:8081 Apache httpd。 如何将所有原始标题传递给错误服务器? 我有以下configuration: server { error_page 404 = http://1.1.1.1:8081/404.php?remote=1; } 当在404.php中检查标题时,我得到客户端的原始ip,但没有来自客户端的cookie; 另外,我得到请求的uri设置为404.php?remote=1而不是导致404错误的url: <?php // 404.php file file_put_content("log.txt", $_SERVER['REQUEST_URI'], FILE_APPEND); // 🙁 file_put_content("log.txt", $_SERVER['REMOTE_ADDR'], FILE_APPEND); // Ok file_put_content("log.txt", $_COOKIE['MyCookie'], FILE_APPEND); // 🙁 empty ?>

nginx:proxy_bind到范围内的随机IP地址

我试图在nginx中configuration一个代理,将所有代理请求绑定到特定范围内的随机IP地址。 每个代理请求将来自不同的IP地址。 我目前有下面的configuration。 但是,由于某些原因,即使configuration加载正常,nginx也不会侦听端口80。 尝试访问服务器时,连接被拒绝。 我是否在谈论这个错误? server { listen 80; listen [::]:80; server_name my.server.name; location / { # proxy all requests to destination proxy_pass https://destination; # generate random IPv6 between IPv6Prefix::0 and IPv6Prefix::13 set_by_lua_block $ip { return 'IPv6Prefix::' .. string.format('%x', math.random(0, 19)) } proxy_bind $ip; # keep connections alive proxy_http_version 1.1; proxy_set_header Connection ''; } […]

将可变pathpath插入nginx位置configuration

我有一个简单的基于用户的图像存储,我有一个主文件夹说'用户',并在其中,我的服务器创build可变的文件夹来存储每个用户的图像。 用于该文件夹的string是随机生成的。 我想要的是将path上的随机string指定为variables。 这里是一个例子 说root /myapp 那么在/myapp/users/里面有/user1 /user2 /user3 …等等 我想expression式去像location /users/{{variableUser}}/cover

在debian上运行一个特定的(较旧的)php版本的nginx,php-fpm

为了迁移旧的PHP软件,我想运行PHP 5.3。*所以我: 通过apt-get purge php*删除了apt-get purge php* 添加相应的http://snapshot.debian.org/archive/debian/到源 安装apt-get install php5=5.3.10-2 现在,如果我做apt-cache policy php5我得到: php5: Installed: 5.3.10-2 Candidate: 5.6.17+dfsg-0+deb8u1 Version table: 5.6.17+dfsg-0+deb8u1 0 500 http://ftp.debian.org/debian/ jessie/main amd64 Packages 5.6.14+dfsg-0+deb8u1 0 500 http://security.debian.org/ jessie/updates/main amd64 Packages *** 5.3.10-2 0 500 http://snapshot.debian.org/archive/debian/20120221T041601Z/ unstable/main amd64 Packages 100 /var/lib/dpkg/status 到目前为止,我的nginx设置如下所示: location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; […]

Nginx的位置索引麻烦

我有nginx位置块的麻烦。 location /myApp/api/account/tutorialPage { alias /data/www/; index tutorial.html; } 如果有严格的匹配 – 一切正常,可以访问我的tutorial.html。 但是我想每个包含/ tutorialPage的链接都会导致tutorial.html。 所以我做了下一个位置: location ~ /tutorialPage { alias /data/www/; index tutorial.html; } 它一定是像“如果链接包含/ tutorialPage比去tutorial.html”。 但是我有403错误。 [错误] 10148#0:* 65346“/ data / www”目录索引被禁止,客户端:194.183.181.44,server:,request:“GET / myApp / api / account / tutorialPage / HTTP / 1.1” “my.domain.com”,推荐人:“ https://my.domain.com/ ” 我有双重检查,数据/ www dir是有chmod 755(例如可以通过enyone读取) —- UPD 工作地点的例子 […]

尝试通过NGINX强制HTTPS用于我的单页应用程序时,AWS ELB运行状况检查失败

我试图强制使用NGINX的http端点上的https,如下所示: server { location / { root /data/www; if ($http_x_forwarded_proto != 'https') { rewrite ^ https://$host$request_uri? permanent; } } location /images/ { root /data; } } 请注意,所有来自nginx的im服务都是静态文件(一个HTML文件,JavaScript文件和一个coupl 我的ELB健康检查打到HTTP:80 /。 所以我认为这是发生,是ELB试图ping我的服务器,打重写,并得到返回301? 我已经看到了许多ruby和node的答案,但这只是静态资产。 帮帮我!

在Laravel(Nginx)子目录上的Flarum

我一直试图把Flarum放在一个子目录上,Laravel在根目录下。 我已经尝试了一些东西,我从服务器得到的唯一的反应是404或laravel index.php下载(当我访问/论坛)。 从我能记得的事情来看,我试过了: 有一个单独的location ~\.php每个子目录。 将php位置放在子目录位置。 在位置尝试根和别名。 我的设置如下: Laravel文件在/ var / www / laravel / public / Flarum文件在/ var / www / forum / /var/run/php5-fpm.sock上的PHP5-FPM Laravel一直在努力完成整个过程,但是我不能设法让工作变得轻松。 server { listen 80; server_name website.web return 301 https://website.web$request_uri; } server { listen 443 ssl; server_name website.web access_log /var/www/logs/access.log; error_log /var/www/logs/error.log warn; ssl_certificate /var/www/ssl/website.chained.crt; ssl_certificate_key /var/www/ssl/website.key; root /var/www/laravel/public/; […]

nginxconfiguration与PHP和别名更新后损坏

我已经通过nginx别名+ php支持configuration了对本地目录的访问: https://mydomain.de/wbg /var/www/wallabag指向/var/www/wallabag 。 一切工作正常,直到我做了一个正常的apt-get update && apt-get升级在服务器上(运行在Debian 8上)。 现在当我打开网站,我只得到“没有指定input文件”。 这是nginx所说的: 2016/02/20 13:07:14 [error] 4376#0: *1 FastCGI sent in stderr: "Unable to open primary script: /var/www/wallabag/index.php/wbg/index.php (No such file or directory)" while reading response header from upstream, client: 78.50.228.24, server: mydomain.de, request: "GET /wbg/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.de" 这是我的configuration的重要部分: server { server_name mydomain.de; […]