---
# System prepended metadata

title: nginx with apache
tags: [Nginx]

---

# nginx with apache

若需同時啟用nginx + apache
1. 修改apache設定檔(/etc/httpd/conf/httpd.conf)

httpd.conf 相關設定修改
:::info
Listen 8080 (原始為80 port，要和nginx不同)
:::

    <VirtualHost *:8080>
    ServerAdmin root@localhost
    ServerName localhost:8080

    <Directory />
        AllowOverride none
        Require all denied
        Header set Access-Control-Allow-Origin "*"
    </Directory>

    <Directory "/usr/share/nginx/html">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Require all granted
        Header set Access-Control-Allow-Origin "*"
    </Directory>
    </VirtualHost>

2. 新增nginx設定檔放置於 **/etc/nginx/conf.d/**，檔名為xxx.conf，內容如下
:::info
server {
    listen       80;
    server_name www.nginx.com nginx.com;

    location / {
        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_redirect off;
        proxy_pass http://127.0.0.1:8080;
    }
}
:::

3.  或許可以試著監聽防火牆的 8080 port
:::info
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
:::

4. 此時即可放入apache相關的套件即可使用
(ex: 將fancy-index資料夾及.htaccess放入 /etc/share/nginx/html 底下)

---
###### tags: `Nginx`