OpenResty Site Configuration Guide for 1Panel

Prerequisites

  • 1Panel installed on the server
  • OpenResty running in a Docker container
  • Existing site working (e.g., web.quickpay.wang)

Step 1: Identify the OpenResty Container Name

1
docker ps | grep openresty

Example output:

1
5f5a06597cca   1panel/openresty:1.27.1.2-5-1-focal   ...   1Panel-openresty-sWqr

What: Find the container name (e.g., 1Panel-openresty-sWqr) — all subsequent docker exec commands need it.

Why: 1Panel’s OpenResty runs inside Docker, so you can’t use the host’s nginx command directly. Container names may change after restart, so reconfirm before each operation.


Step 2: Create the Site Directory and Add Files

1
2
3
4
5
6
7
8
# Create site directory (host path)
mkdir -p /opt/1panel/www/preview

# Copy website files
cp -r /root/projrects/qt-browser/prototype/* /opt/1panel/www/preview/

# Verify files are in place
ls -la /opt/1panel/www/preview/

What: Create a subdirectory under /opt/1panel/www/ and place your website files there.

Why: /opt/1panel/www/ maps to /www/ inside the OpenResty container. Creating a subfolder here is equivalent to creating a subpath in the web root.

Path mapping:

Host PathContainer Path
/opt/1panel/www/preview//www/preview/
/opt/1panel/www/conf.d//usr/local/openresty/nginx/conf/conf.d/

Step 3: Write the Nginx Configuration File

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
cat > /opt/1panel/www/conf.d/preview.quickpay.wang.conf << 'EOF'
server {
    listen 8025;
    listen [::]:8025;
    server_name preview.quickpay.wang;

    root /www/preview;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
EOF

What: Create a .conf file named after the domain in /opt/1panel/www/conf.d/.

Why: OpenResty’s main config includes conf.d/*.conf, so placing files there auto-loads them without modifying the main configuration.

Configuration explained:

DirectiveMeaning
listen 8025Listen on port 8025
server_name preview.quickpay.wangMatch requests for this domain
root /www/previewWebsite files path inside container
try_files $uri $uri/ =404Look for files in order, return 404 if not found

Step 4: Test Configuration Syntax

1
docker exec 1Panel-openresty-sWqr nginx -t

What: Check the configuration file for syntax errors.

Why: A misconfigured reload can stop all OpenResty services. Testing first is a mandatory safety step.

Expected output:

1
2
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

If it fails: Check for missing semicolons, typos, or path errors, then retest.


Step 5: Reload Configuration

1
docker exec 1Panel-openresty-sWqr nginx -s reload

What: Reload all configuration files to activate the new site.

Why: reload is a graceful operation that doesn’t interrupt existing connections. It’s the recommended approach for production environments.

Verify it worked:

1
2
3
4
5
# Check if port is listening
ss -tlnp | grep 8025

# Test page access
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8025/index.html

Returns 200 on success.


Step 6: Open Port (If Needed)

If the server has a firewall or cloud security group:

1
2
3
4
5
# UFW
sudo ufw allow 8025/tcp

# Or iptables
sudo iptables -A INPUT -p tcp --dport 8025 -j ACCEPT

Also add an inbound rule in your cloud console (Alibaba Cloud, Tencent Cloud, AWS, etc.) allowing TCP 8025.

Why: Even with correct Nginx config, if the port isn’t open, external requests can’t reach the server.


Access Verification

Open in browser:

1
http://preview.quickpay.wang:8025

Complete Workflow (Copy-Paste Ready)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 1. Confirm container name
docker ps | grep openresty

# 2. Create site directory and add files
mkdir -p /opt/1panel/www/preview
cp -r /root/projrects/qt-browser/prototype/* /opt/1panel/www/preview/

# 3. Write Nginx config
cat > /opt/1panel/www/conf.d/preview.quickpay.wang.conf << 'EOF'
server {
    listen 8025;
    listen [::]:8025;
    server_name preview.quickpay.wang;

    root /www/preview;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}
EOF

# 4. Test config
docker exec 1Panel-openresty-sWqr nginx -t

# 5. Reload
docker exec 1Panel-openresty-sWqr nginx -s reload

# 6. Verify
ss -tlnp | grep 8025
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8025/index.html

Troubleshooting

ProblemCauseSolution
nginx -t failsSyntax error in configCheck semicolons, brackets, paths
Port not listeningConfig not reloaded or wrong container nameReconfirm container name and reload
External access failsFirewall/security group not openOpen the corresponding port
403 ForbiddenDirectory permissions or missing index fileCheck file permissions and directory structure
404 Not FoundWrong root pathConfirm container path is /www/xxx