【问题标题】:PHP app deploy Ubuntu 16.04 nginx apache settingPHP 应用程序部署 Ubuntu 16.04 nginx apache 设置
【发布时间】:2017-07-08 12:51:14
【问题描述】:

我正在尝试部署一个小 php 应用程序已经是第三天了。 我们将我们的应用程序(即 3 个 rails 应用程序和 1 个 php)移动到同一台服务器上。 Rails 应用程序运行良好。 PHP 没有。 我从来没有真正部署过 PHP 应用程序,所以我是通过指南来完成的。到目前为止,我得到了这种情况: 如果我尝试在浏览器中打开 PHP 应用程序,我会看到默认的 Apache 页面。如果我刷新页面,它将显示 index.php 文件的内容,但显示为空白文本。再次刷新 - 默认 Apache 页面,然后再次刷新 - index.php 的内容。

我的设置:

nginx/sites-available/my.site(在启用的站点中启用)

server {
     listen 80 default_server;
     listen [::]:80 default_server;

 root /var/www/my.site/httpdocs;

 # Add index.php to the list if you are using PHP
 index index.php index.html index.htm index.nginx-debian.html;

 server_name my.site www.my.site;

 location / {
   proxy_pass http://localhost:8000;
   include /etc/nginx/proxy_params;
 }

 location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires      30d;
 }

 location @proxy {
    proxy_pass http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
 }
 location ~* \.php$ {
    proxy_pass http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
 }
}

apache2/sites-available/my.site

ServerName my.site
ServerAlias www.my.site

ServerAdmin webmaster@localhost
DocumentRoot /var/www/my.site/httpdocs

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

apache2/ports.conf

NameVirtualHost 127.0.0.1:8000
Listen 8000

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

在休息日工作,不知道如何修复服务器。任何建议表示赞赏。

【问题讨论】:

  • 我能知道你为什么使用 nginx 作为 apache 的代理吗?
  • @Albert221 我没有合适的答案。我刚开始 google 'ubuntu php apache deploy' 并且这些指南出现了。你能提供更好的解决方案吗?
  • 我认为您不了解您要达到的目标。 Nginx 和 Apache 都是网络服务器,而 PHP 是一个(非常普遍的)解释 .php 代码的程序。您通常不希望同时使用 nginx 和 apache。阅读这两个并选择更符合您要求的一个:digitalocean.com/community/tutorials/…

标签: php apache nginx


【解决方案1】:

nginx 配置

map $sent_http_content_type $expires {
    default               off;
    ~css                  max;
    ~javascript       max;
    ~image             max;
    ~font-woff        max;
    ~video               max;
    ~zip                   max;
    ~txt                    max;
  }
expires                 $expires;

server {
listen 80;
    server_name exemple.com;
    root /home/to/exemple.com;
    index index.php index.html;             

gzip                    on;
gzip_min_length         128;
gzip_http_version       1.1;
gzip_buffers           128 32k;
gzip_types
    text/css
    text/javascript
    text/xml
    text/plain
    text/x-component
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    application/atom+xml
    font/truetype
    font/opentype
    application/vnd.ms-fontobject
    image/svg+xml;
gzip_static  on;    
gzip_proxied            expired no-cache no-store private auth;
gzip_disable            "msie6";
gzip_vary                on;

location / {
   proxy_pass http://127.0.0.1:8000;
   proxy_set_header Host $host; 
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   }
}

apache 配置

php 7 模组

apt install libapache2-mod-php7.0

php5 模组

apt install libapache2-mod-php

包括例如 php7.0 mod

a2enmod php7.0

虚拟主机配置 apache

<VirtualHost *:8000>
  ServerName exemple.com
  DocumentRoot /home/to/exemple.com
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  RewriteEngine On
<Directory /home/to/exemple.com/>
  php_admin_flag engine on
  Options -ExecCGI -Indexes +FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>
</VirtualHost>

删除 apache2.conf 中的 NameVirtualHost 127.0.0.1:8000 粘贴 ServerName 127.0.0.1

systemctl restart apache2
systemctl restart nginx

原帖apache2+nginx proxy

【讨论】:

    猜你喜欢
    • 2017-08-11
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 2017-03-10
    • 2021-12-14
    相关资源
    最近更新 更多