AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-384320

Dave's questions

Martin Hope
Dave
Asked: 2018-05-12 11:30:28 +0800 CST

为什么我的 Nginx 别名指令不起作用?

  • 1

我在 CentOS 7 上使用 Nginx 和 Ruby on Rails / Puma。我希望 RoR 跳过某些文件路径并直接由 Nginx 提供服务。我在我的网站的“服务器”块中创建了这个

location /assets/lib/ {
    alias /home/rails/myproject_production/app/assets/javascripts/lib/;
    autoindex off;
}

但是,当我调用类似的资产时http://www.mydomein.com/assets/lib/myfile.js,我得到一个 404。这就是我的日志中出现的内容

2018/05/11 15:21:47 [error] 242#0: *1 open() "/home/rails/myproject_production/public/assets/lib/myfile.js" failed (2: No such file or directory), client: 50.240.135.5, server: www.mydomein.com, request: "GET /assets/lib/myfile.js HTTP/1.1", host: "www.mydomein.com"

从日志中,似乎根本没有调用别名。我在上面缺少什么?我的完整配置如下

upstream myproject {
  server unix:///home/rails/myproject_production/shared/sockets/puma.sock;
}

# Listener for Apex Domain
server {
  listen 80;
  server_name www.mydomein.com;
  root /home/rails/myproject_production/public; # I assume your app is located at this location

  location / {
    proxy_pass http://myproject; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    if ($request_uri ~* "(\/image\/.*)|(.*\.(ico|gif|jpe?g|png)$)") {
      expires 60d;
      access_log off;
      add_header Pragma public;
      add_header Cache-Control "public";
      break;
    }
  }

  location /assets/lib/ {
        alias /home/rails/myproject_production/app/assets/javascripts/lib/;
        autoindex off;
  }

  location /cable {
    proxy_pass http://myproject;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }

}
nginx
  • 1 个回答
  • 893 Views
Martin Hope
Dave
Asked: 2018-03-07 07:02:58 +0800 CST

如何设置 MX 记录以将邮件路由到我的 CentOS 7 Postfix 服务器?

  • 0

我正在尝试设置从我的 CentOS Postfix 邮件服务器到我的 gmail 帐户的邮件转发,并且我想确保在对 PostFix 配置进行故障排除之前正确创建 MX 记录。在我的托管公司控制面板的 DNS 设置部分,我创建了这条记录

HostName: @
Record Type: MX Record
Address: example.com.
Priority: 10

我也有这些属性的 A 名记录

HostName: example.com
Record Type: A (Address)
Address: 162.155.38.22
Priority: n/a

然而,尽管我看到 postfix 在我的 CentOS 7 机器上运行

[root@server /]# ps aux | grep postfix
root     17979  0.0  0.1  89488  1244 ?        Ss   Mar05   0:00 /usr/libexec/postfix/master -w
postfix  17981  0.0  0.2  89768  2532 ?        S    Mar05   0:00 qmgr -l -t unix -u
postfix  22093  0.0  0.3  89592  4020 ?        S    09:40   0:00 pickup -l -t unix -u
root     22167  0.0  0.0   9000   924 pts/0    S+   09:52   0:00 grep --color=auto postfix

在我向 admin@example.com 发送一封电子邮件后,我在日志中没有看到任何关于收到电子邮件的信息。我是否正确设置了 MX 记录?

centos
  • 1 个回答
  • 5073 Views
Martin Hope
Dave
Asked: 2018-03-04 10:26:53 +0800 CST

哪些标头优先 - 由 Nginx 或应用程序服务器设置的标头?

  • 0

我在带有 Rails 服务器的 CentOS 上使用 Nginx。我对如何设置标题感到困惑。如果 Nginx 设置标头和应用程序服务器(本例中为 Ruby on Rails),哪一个胜出?我有这个 Nginx 服务器块

server {
  listen 80;
  server_name www.example.com;
  root /home/rails/scale_production/public; # I assume your app is located at this location

  location / {
    proxy_pass http://scale; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    if ($request_uri ~* "($\/image\/.*)|(.*\.(ico|gif|jpe?g|png)$)") {
      expires 60d;
      access_log off;
      add_header Pragma public;
      add_header Cache-Control "public";
      break;
    }
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }

但是,当我调用与我的正则表达式之一匹配的 URL 时,我没有看到缓存标头被设置....

localhost:tmp davea$ curl -I "http://www.example.com/people/image/27"
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 03 Mar 2018 18:20:43 GMT
Content-Type: image/jpeg; charset=binary
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Expires: Sun, 03 Mar 2019 18:20:43 GMT
Content-Disposition: inline; filename="Bill Smith"
Content-Transfer-Encoding: binary
Cache-Control: private
ETag: W/"b0c3f986a9c7f967e58733702e71a395"
X-Request-Id: 2f9728bb-3b6f-4d67-9344-afc1e29cacd5
X-Runtime: 0.007781

所以我想知道为什么会这样。我是在我的块中做错了什么,还是在我的应用程序服务器中设置了覆盖 Nginx 标头的标头?

nginx
  • 1 个回答
  • 336 Views
Martin Hope
Dave
Asked: 2018-03-03 16:01:12 +0800 CST

如何在 Nginx 位置块中正确编写“或”语句?

  • 5

我在 CentOS 7 上使用 Nginx。我想为以特定扩展名结尾或在 URL 中包含“/image/”字符串的文件添加缓存控制标头。我试过这个

  location / {
    proxy_pass http://scale; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    if ($request_uri ~* ".(ico|gif|jpe?g|png)$") | ($request_uri ~* "/image/") {
      expires 60d;
      access_log off;
      add_header Pragma public;
      add_header Cache-Control "public";
      break;
    }
  }

但是在重新启动服务器后,我得到了一个

invalid condition "$request_uri" in /etc/nginx/conf.d/scale.conf:16

错误。如果我从有问题的行中删除 " | ($request_uri ~* "/image/")" ,所有重新启动都很好,但是我无法匹配我想要的东西。如何在我的配置文件中编写正确的 or 语句?

nginx
  • 1 个回答
  • 10164 Views
Martin Hope
Dave
Asked: 2018-03-02 12:01:17 +0800 CST

在 nginx 中替换非 www 域时遇到问题

  • 1

我正在使用带有 Nginx 的 CentOS 7。我想将所有非 www 域转换为“www”域,例如,如果有人输入“abc.example.com”,我希望将它们重定向到“www.example.com”。我试过这个

server {
  listen 80;
  server_name "~^(?!www\.).*";
  return 301 $scheme://www.$host$request_uri;
}

在我的站点特定配置文件中,但是如果有人输入“abc.example.com”,他们会被重定向到“www.abc.example.com”。如何更正上述内容以替换而不是预先添加“www”?

nginx
  • 1 个回答
  • 34 Views
Martin Hope
Dave
Asked: 2018-03-01 13:51:11 +0800 CST

如何设置我的 nginx 权限以允许多部分表单提交?

  • 1

我在 CentOS 7 上使用 Nginx 和 Puma(用于 Rails 应用程序)。我对如何设置文件上传权限感到困惑。目前,当我尝试上传文件(提交多部分表单)时,我在 nginx 错误日志中收到以下错误

2018/02/28 16:35:48 [crit] 31241#0: *148 open() "/var/lib/nginx/tmp/client_body/0000000006" failed (13: Permission denied), client: 96.92.233.165, server: example.com, request: "POST /people HTTP/1.1", host: "example.com", referrer: "http://example.com/people/new"

我试图让所有东西都以“rails”用户身份运行。以下是我的 nginx 和 puma 进程

[root@server /]# ps -elf | grep nginx
0 S root       944   920  0  80   0 -  2249 pipe_w 16:38 pts/1    00:00:00 grep --color=auto nginx
1 S root     31238     1  0  80   0 - 30712 rt_sig 15:06 ?        00:00:00 nginx: master process /usr/sbin/nginx
5 S rails    31239 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31240 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31241 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
5 S rails    31242 31238  0  80   0 - 30843 ep_pol 15:06 ?        00:00:00 nginx: worker process
[root@server /]# ps -elf | grep puma
1 S rails      582     1  0  80   0 - 135430 poll_s 16:19 ?       00:00:00 puma 3.11.2 (tcp://0.0.0.0:3000,unix:///home/rails/scale_production/shared/sockets/puma.sock) [scale_production]
1 S rails      590   582  0  80   0 - 286725 futex_ 16:19 ?       00:00:02 puma: cluster worker 0: 582 [scale_production]
1 S rails      594   582  0  80   0 - 287282 futex_ 16:19 ?       00:00:03 puma: cluster worker 1: 582 [scale_production]
1 S rails      596   582  0  80   0 - 287255 futex_ 16:19 ?       00:00:02 puma: cluster worker 2: 582 [scale_production]
1 S rails      599   582  0  80   0 - 286939 futex_ 16:19 ?       00:00:02 puma: cluster worker 3: 582 [scale_production]
0 S root       946   920  0  80   0 -  2250 pipe_w 16:38 pts/1    00:00:00 grep --color=auto puma

以下是有问题的目录的权限。为了使它起作用,我还应该设置什么?

[root@server /]# ls -al /var/lib/nginx
total 12
drwx------  3  755 rails 4096 Feb 24 14:33 .
drwxr-xr-x 23 root root  4096 Feb 24 14:33 ..
drwx------  7  755 rails 4096 Feb 24 15:06 tmp
[root@server /]# ls -al /var/lib/nginx/tmp/client_body
total 8
drwx------ 2 rails rails 4096 Feb 24 15:06 .
drwx------ 7   755 rails 4096 Feb 24 15:06 ..
[root@server /]# ls -al /var/lib/nginx/tmp
total 28
drwx------ 7   755 rails 4096 Feb 24 15:06 .
drwx------ 3   755 rails 4096 Feb 24 14:33 ..
drwx------ 2 rails rails 4096 Feb 24 15:06 client_body
drwx------ 2 rails rails 4096 Feb 24 15:06 fastcgi
drwx------ 2 rails rails 4096 Feb 24 15:06 proxy
drwx------ 2 rails rails 4096 Feb 24 15:06 scgi
drwx------ 2 rails rails 4096 Feb 24 15:06 uwsgi
nginx
  • 2 个回答
  • 2217 Views
Martin Hope
Dave
Asked: 2018-03-01 09:56:19 +0800 CST

如何在 CentOS 上将子域重定向到 Nginx 中的根域?

  • 1

我将 Centos 与 Nginx 和 Puma 一起使用。我想将所有子域重定向到我的主根域,所以我按照这里的说明进行操作 - https://stackoverflow.com/questions/26801479/nginx-redirect-all-subdomains-to-main-domain。但是我无法让它工作。下面是我的配置

upstream projecta {
  server unix:///home/rails/projecta_production/shared/sockets/puma.sock;
}

server {
  listen 80;
  server_name mydomein.com;
  return 301 http://mydomein.com$request_uri;
  root /home/rails/projecta_production/public; # I assume your app is located at this location

  location / {
    proxy_pass http://projecta; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

如果我排除“return 301 http://mydomein.com $request_uri;” 行,那么我的站点将在根域上运行,但不能在任何子域上运行(例如,查看子域将产生默认的 Nginx 索引页面)。如何将所有子域重定向到我的主域并保留我的 Rails/Puma 配置?

nginx
  • 1 个回答
  • 2265 Views
Martin Hope
Dave
Asked: 2016-11-05 18:27:57 +0800 CST

如何设置我的 nginx 文件来重写我的 URL?

  • 0

我在 Ubuntu 14.04 上使用 nginx (1.4.6-1ubuntu3.4)。例如,当有人访问一个页面时http://mymaindomain.com/page1,我想重写它以包含www子域。因此,如果有人访问了之前的 URL,则重写后的 URL 将是http://www.mymaindomain.com/page1. 所以我添加了一个“服务器”指令:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
…
}

server {
  server_name mymaindomain.com;
  rewrite ^ http://www.mymaindomain.com$request_uri permanent;
}

到我/etc/nginx/nginx.conf文件的末尾。但是重新启动服务器后,我收到错误消息:

2016/11/04 22:12:33 [emerg] 1063#0: "server" directive is not allowed here in /etc/nginx/nginx.conf:75

设置我的 nginx 服务器以正确重写我的 URL 的正确方法是什么?

rewrite nginx conf
  • 1 个回答
  • 114 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve