【Nginx重定向到外部URL】教程文章相关的互联网学习教程文章

带有和不带斜杠的Nginx永久重定向【代码】

我找不到任何方法来使用和不使用尾部斜杠的URL重定向工作. 每当访问example.com/info和example.com/info/的网址都会转到example.com/info-page/并在网址后面添加“-page”字符串时,我想这样做.location /info/ {rewrite ^(/info)(.*)$http://example.com/$1-page/ permanent; }我怎样才能实现这一目标?解决方法:你不需要位置,只需使用:rewrite ^/info/?$http://$host/info-page/ permanent;要么if ($request_uri !~ "^/info/?$")...

nginx不会重定向404错误【代码】

在我的网站上我只有两个页面“index.php”和“page.php”,无论我输入什么,我都被重定向到localhost,例如,如果我去localhost / randompage而不是被重定向到404.html我转到localhost (即index.php) 这是我的conf:server {listen 80;server_name localhost; root html; index index.php;location / {if ($request_uri !~* '\/|page\.php\?.*') {return 404;}try_files $uri $uri/ /index.php;}error_page 404 ...

nginx – 重定向除一个子域外的所有子域?【代码】

我有一个域example.com,并希望将所有子域重定向到http://example.com.但是一个例外是api.example.com的后端子域. 如何使用Nginx将其关闭?解决方法:您可以使用多个服务器的组合(包括带有通配符子域的服务器).以下是此类配置的最小示例:server {listen 80;server_name api.example.com;add_header Content-Type text/plain;return 200 "api"; } server {listen 80;server_name *.example.c...

Nginx:重定向期间保留端口【代码】

我有一个Nginx服务器在一个Docker容器内监听80. 在Nginx配置中,我需要在特定情况下执行重定向到静态页面.rewrite ^ /foobar.html redirect;用户可以使用docker命令行运行容器指定任何端口(作为参考,她可以在端口8000上公开容器,内部Nginx仍将使用80). 现在,当Nginx重定向URL时,端口将替换为Nginx内部使用的端口,而不是使用Docker使用的端口. 我试图设置一堆标题,但他们没有帮助:proxy_set_header X-Forwarded-Host $host:$server_...

套接字 – 将nginx位置重定向/重写为.sock文件,不带前缀【代码】

我有一台服务器上运行了几个API.其中一个是用户-DB以下内容很简单:location /usersDB/ {include proxy_params;proxy_pass http://unix:/home/ubuntu/projects/UsersDB-api/app.sock; }除非我尝试访问usersDB API的/ helloWorld路由,并查看gunicorn.err的日志,我看到:GET /usersDB/helloWorld我希望看到:GET /helloWorld当然,gunicorn会返回404,这就是我在浏览器中看到的内容.我尝试过重写规则:location /usersDB/ {rewrite /us...

Nginx将所有子域重定向到主域【代码】

我正在尝试将所有子域重定向到我的主域,但到目前为止它无效.我是这样做的:server {listen [::]:80;server_name *.example.com;return 301 $scheme://example.com$request_uri; } server {listen [::]:443;server_name example.com;ssl on;ssl_certificate /etc/ssl/certs/example.com.crt;ssl_certificate_key /etc/ssl/private/example.com.key;#enables all versions of TLS, but not SSLv2 or 3 which are weak and no...

nginx – 拒绝所有不阻止返回重定向【代码】

Nginx对我来说意外表现.这是两个简化的位置块. 这按预期工作.返回403错误:location / {deny all;root /var/www/test; }我预计403错误.但是,这会返回301并重定向:location / {deny all;return 301 https://$server_name$request_uri; }如何使用return指令拒绝和阻止任何url重定向?解决方法:在nginx中,return指令来自重写模块,而deny来自access模块??.根据nginx document和源代码,在NGX_HTTP_REWRITE_PHASE阶段处理重写模块(用于在...

linux – Nginx反向代理重定向【代码】

我使用nginx作为反向代理,当我登录我的Web界面时,我被重定向到代理的URL.我想避免它,并始终将“server_name”保留为URL.可能吗? 这是我的/etc/nginx/conf.d/my_app.conf:server { listen 443 ssl; server_name my-app.net; ssl_certificate /etc/pki/tls/certs/my-app.cer; ssl_certificate_key /etc/pki/tls/private/my-app.key; ssl_protocols TLSv1.1 TLSv1.2; access_log /var/log/nginx/my-app.access.log main; location /...

Nginx动态代理重定向【代码】

我希望能达到这样的目的:location = / {if ($args ~ "^url=(.+)") { #gets the "url" get parameterset $key1 $1;proxy_pass $key1; #use the parameter as proxy address} }这甚至可能吗?解决方法: location / {proxy_pass http://backend$arg_url; }> http://nginx.org/r/proxy_pass> http://nginx.org/en/docs/http/ngx_http_core_module.html#variables> http://wiki.nginx.org/IfIsEvil

wordpress – Nginx’重写或内部重定向循环,同时内部重定向’导致500【代码】

我对Raspbian喘息的nginx 1.2.1-2.2有点问题.我认为它是在我更改了我的sites-available / default文件中的索引之后开始的.以下是相关文件:nginx.conf user www-data; worker_processes 4; pid /var/run/nginx.pid;events {worker_connections 768;# multi_accept on; }http {### Basic Settings##sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;index index.html index.htm index.php;...

django – 为什么Nginx会继续将我重定向到localhost?【代码】

在Gunicorn的后端使用Django,每次我提交表单并且应该发送到example.com/pagetwo时,我会被发送到localhost / pagetwo. 我是Nginx的新手,所以如果有人能指出问题是什么我会是最棒的:) default.conf:server {listen 80;server_name example.com;location /static/ {root /srv;}location / {proxy_redirect off;proxy_pass http://unix:/srv/sockets/website.sock;}error_page 500 502 503 504 /50x.html;location = /50x.h...

通过Varnish / Apache在WordPress上使用Nginx SSL终止重定向循环【代码】

我有一个设置,其中Apache在端口80上的Varnish 4后面监听端口8080,但是我的客户端需要ssl在网站上工作,所以我使用this guide在端口443上设置Nginx用于SSL终止. 一切都在http上工作正常,但在尝试在https上加载网站时,网站所需的脚本将无法加载,因此我决定更改设置中的网站网址>一般到https网址,保存更改后,我在Chrome中遇到重定向循环错误. 我无法访问该网站的wordpress仪表板来更改网址,所以我必须通过phpmyadmin这样做.但是现在当通...

nginx位置修复:重定向到index.html【代码】

我正在运行nginx v 1.0.4,我们正在尝试执行以下操作:location ~ ^/${rewrite ?^.*$?/index.html ?last; }基本上:如果用户到达默认域http://www.foo.com或http://www.foo.com/将其重定向到http://www.foo.com/index.html 当我将其添加到我的conf文件中时,我得到以下内容:在/etc/nginx/myconf.conf中启动nginx:nginx:[emerg] unknown指令“” 提前致谢.解决方法:您可以在没有位置的情况下使用重写功能rewrite ^/$ /index.html ...

NGINX:仅基于特定URL的cookie重定向用户【代码】

我正在构建一个封闭的社交网络,目前当用户未登录时,他们将始终被重定向到我的域的主页. 我想做的是做以下事情: >使用NGINX检查用户是否已登录(通过检查cookie),然后当他们转到主页(mydomain.com)时重定向到mydomain.com/newsfeed.>此检查仅应在用户浏览主页时应用,并且不应在任何其他网址上工作(否则将始终重定向). 我是NGINX的新手,并查看了使用cookie进行重定向的各种教程但未能得到答案(最明显的是将重定向限制为仅限主页). 提...

如何将所有请求重定向到nginx中的同一文件?

我的根目录 /网络/应用/ src目录 在这个目录中我有2个目录/ js /和/ assets /和一个文件index.html 这就是我需要实现的目标: 对/ js /或/ assets /或/index.html的任何请求只是从根目录提供文件例如来自/ web / app / src / js /目录的myapp.com/js/app.js服务器app.js与/ assets /的请求相同 但所有其他请求,任何其他uri应该导致服务index.html 例如 myapp.com/bla/bla/q?param=x应该从web根目录提供index.html 所有重写都应该是...