我已经重新设计了一个网站并更改了网址格式。现在,我需要将旧网址更改为新网址。
这是我的旧网址:
http://www.example.com/forum/showPost/2556/Urgent-Respose
Run Code Online (Sandbox Code Playgroud)
新的网址将是:
http://www.example.com/2556/Urgent-Respose
Run Code Online (Sandbox Code Playgroud)
如何通过/forum/showPost从网址中删除使用Nginx重定向到新网址?
编辑:也是这个网址:
http://www.tikshare.com/business/showDetails/1/Pulkit-Sharma-and-Associates,-Chartered-Accountants-in-Bangalore
Run Code Online (Sandbox Code Playgroud)
新网址:
http://www.tikshare.com/classifieds/1/Pulkit-Sharma-and-Associates,-Chartered-Accountants-in-Bangalore
Run Code Online (Sandbox Code Playgroud)
以上链接已完全删除,而该链接将替换business/showDetails为classifieds
当我请求链接http://abc.example.com/images/default-thumbnail.jpg时,在查看日志文件输出时发生 404 错误[error] 1244#0: *1 open() "/tmp/upload-dir/images/default-thumbnail.jpg" failed (2: No such file or directory),
但实际上这个文件是有的,而且权限是777
[root@localhost nginx]# ll /tmp/upload-dir/images/default-thumbnail.jpg
-rwxrwxrwx 1 root root 7592 6? 21 2016 /tmp/upload-dir/images/default-thumbnail.jpg
Run Code Online (Sandbox Code Playgroud)
nginx配置?
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
listen 80;
server_name abc.example.com;
access_log /www/abc/logs/nginx-access.log;
error_log /www/abc/logs/nginx-error.log;
root /tmp/upload-dir;
location /images/ {
autoindex on;
expires 30d;
}
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试将响应标头添加到仅提供一个位置路径,并且 nginx 配置如下所示
server {
...
add_header x-test test;
location /my.img {
rewrite ^/my.img$ /119.img;
add_header x-amz-meta-sig 1234567890abcdef;
}
}
Run Code Online (Sandbox Code Playgroud)
但只有顶级标头(x-test)有效,位置指令中的标头不会显示,如图所示
$ curl -v -o /tmp/test.img 'https://www.example.com/my.img'
< HTTP/1.1 200 OK
< Server: nginx/1.9.3 (Ubuntu)
< Date: Sun, 14 May 2017 23:58:08 GMT
< Content-Type: application/octet-stream
< Content-Length: 251656
< Last-Modified: Fri, 03 Mar 2017 04:57:47 GMT
< Connection: keep-alive
< ETag: "58b8f7cb-3d708"
< x-test: test
< Accept-Ranges: bytes
<
{ [16104 bytes data]
Run Code Online (Sandbox Code Playgroud)
如何仅针对所服务的特定文件发回自定义 headrr。
我目前正在使用URL路径的JS项目上工作。现在,如果我使用example.com/进入我的网站,则JavaScript将无法工作,因为我实际上需要example.com/index.html。
我已经在使用反向代理来代理传递给两个不同的Docker容器。所以我的想法是将请求传递给example.com/index.html时example.com/被调用。但是我不知道要实现这个目标的正则表达式的东西。
我的旧配置:
server {
listen 80;
server_name example.com;
# allow large uploads of files - refer to nginx documentation
client_max_body_size 1G;
# optimize downloading files larger than 1G - refer to nginx doc
before adjusting
#proxy_max_temp_file_size 2G;
location / {
proxy_pass http://structure.example:80;
}
location /cdn {
proxy_pass http://content.example:80;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的东西:
server {
listen 80;
server_name example.com;
# …Run Code Online (Sandbox Code Playgroud) 我试图让我的 Nginx 更加枯燥,因为它充当了近 20 台服务器的反向代理。这是我正在尝试做的,所有主机名和内容都已更改/示例:
map $http_host $backend {
baz.mydomain.com hostname1:8080;
foo.mydomain.com 192.168.1.10:8081;
bar.mydomain.com hostname2:1234;
ham.mydomain.com hostname2:5678;
}
server {
listen 443 ssl http2;
server_name .mydomain.com;
ssl_certificate /usr/share/nginx/certs/mydomain.com.pem;
ssl_certificate_key /usr/share/nginx/certs/mydomain.com.key;
location / {
proxy_redirect http:// https://;
proxy_pass http://$backend;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,无论如何,这总是会出现错误的网关错误。我已经尝试了一些变体和移动的东西,有和没有通配符 server_name,用 $host 而不是 $http_host 但到目前为止我无法让它工作。我什至以正确的方式解决这个问题吗?我真的不想在我的配置中有将近 20 个单独的虚拟服务器条目。
在 nginx 文档中没有很多关于使用这样的地图的帮助,除了一篇非常老的帖子在此处简要提到类似的内容:https : //serverfault.com/questions/342309/how -to-write-a-dry-modular-nginx-conf-reverse-proxy-with-named-locations
我想登录$request_body访问日志。
但是一些请求有一些敏感的 JSON 字段,如密码。
例子:
[2019-03-28] 201 - POST /api/user/add HTTP/1.1 - {\x22email\x22:\x22test@test.com\x22,\x22password\x22:\x22myPassword\x22}
Run Code Online (Sandbox Code Playgroud)
有没有办法混淆密码值,使输出看起来像这样:
[2019-03-28] 201 - POST /api/user/add HTTP/1.1 - {\x22email\x22:\x22test@test.com\x22,\x22password\x22:\x22****\x22}
Run Code Online (Sandbox Code Playgroud) 我尝试在 nginx.conf 中添加一个 proxy_pass 像
location /example/ {
proxy_pass http://example.com;
}
Run Code Online (Sandbox Code Playgroud)
但不是在 conf 文件中硬编码http://example.com我想在环境变量中使用这个值。
如何在 nginx.conf 中使用环境变量?或者有没有更好的 nginx 没有外部配置的方法?
Nginx(docker image,1.17.2)需要对子路径进行基本身份验证。尽管我的配置另有说明https://example.org/subpath:
// /etc/nginx/conf.d/mysetup.conf
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server {
listen 443 ssl;
server_name example.org;
server_tokens off;
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
access_log /var/logs/nginx/example.org.access.log;
error_log /var/logs/nginx/example.org.error.log info;
root /var/www/domains/example.org/stage_root/;
location / {
auth_basic "example.org server";
auth_basic_user_file /var/htaccess/htaccess_example.org;
}
location /subpath {
auth_basic off;
root /var/www/domains/example.org/;
}
}
Run Code Online (Sandbox Code Playgroud)
一些事实:
server指令中)和上游丛。docker-compose其自己网络设置的一部分(nginx 是网关)/var/www/domains/example.org/subpath/auth_basic会禁用身份验证请求到目前为止我尝试过的:
location /块移至该server …我在 nginx 中配置了一台服务器,并使用以下代码来创建我的速率限制区域:
limit_req_zone $key zone=six_zone:10m rate=60r/m;
在我的位置,我使用一个模块来满足请求。该位置支持 GET、POST 和 DELETE 方法。我正在尝试仅对对该位置的 GET 请求进行速率限制。我认为这可能有效,但事实并非如此。
location /api/ {
if ($request_method = GET) {
limit_req zone=six_zone;
}
reqfwder;
}
Run Code Online (Sandbox Code Playgroud)
对我如何解决这个问题有任何帮助或指示吗?谢谢。
我正在尝试在 Nginx 服务器上运行带有 Node.js 后端的 React 应用程序。
这是 nginx.conf 文件中我的服务器块:
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/folder-name/frontend/build;
index index.html index.htm;
location / {
proxy_pass http://localhost:5000;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Run Code Online (Sandbox Code Playgroud)
该build文件夹包含编译后的react js代码(使用npm run build) Node.js 后端使用 pm2/forever 在端口 5000 上运行。
重启Nginx服务器后,服务器IP上出现react UI,但UI扭曲。另外,我无法访问我的后端 APIMyIP/api/endpoint …